public class ImgServlet extends HttpServlet
{
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void destroy()
{
}
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
{
try
{
Font font
= Font.
decode("Arial-BOLD-18");
int width = (int) bounds.getWidth();
int height = (int) bounds.getHeight();
for (Enumeration e
=request.
getHeaderNames(); e.
hasMoreElements() ;)
if (e==null)
break;
else
{
text=h+" : "+request.getHeader(h)+"\n";
v.add(text);
bounds = font.getStringBounds(text,fc);
if (bounds.getWidth()>width)
width=(int)bounds.getWidth();
height+=bounds.getHeight();
}
text="Remote Address : "+request.getRemoteAddr()+"\n";
v.add(text);
if (bounds.getWidth()>width)
width=(int)bounds.getWidth();
height+=bounds.getHeight();
text="Remote Host : "+request.getRemoteHost()+"\n";
v.add(text);
if
(bounds.getWidth()>width)
width=(int)bounds.getWidth();
height+=bounds.getHeight();
text="Server Name : "+request.getServerName()+"\n";
v.add(text);
if (bounds.getWidth()>width)
width=(int)bounds.getWidth();
height+=bounds.getHeight();
text="Protocol : "+request.getProtocol()+"\n";
v.add(text);
if (bounds.getWidth()>width)
width=(int)bounds.getWidth();
height+=bounds.getHeight();
g2 = buffer.createGraphics();
g2.setFont(font);
g2.setColor(background);
g2.fillRect(0,0,width,height);
g2.setColor(color);
for (int j=0; j<v.size();j++)
{
g2.
drawString((String)v.
elementAt(j
),
0,
(int)-bounds.
getY()*j
+20);
}
response.setContentType("image/jpeg");
ImageIO.write(buffer, "jpeg", os);
os.close();
}
{
response.setContentType("text/html");
out.println( "** Error ** " );
ex.printStackTrace(out);
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
{
processRequest(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
{
processRequest(request, response);
}
public String getServletInfo
()
{
return "The servlet displays HTTP headers!";
}
}