Structure Query Language, C programming, Java, Servlet, Jsp, Unix

Tuesday, 14 February 2012

Write a Servlet to display all the attributes available from request and context.


import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class pro13 extends HttpServlet
{
 public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
 {
  res.setContentType("text/html");
  PrintWriter out=res.getWriter();
  out.printf("<html><head><title>2ND PROGRAM-pankaj</title></head><body bgcolor='limegreen'>");
  out.println("<table border=1 align='center' width=60%><caption>ATTRIBUTE NAME AND THEIR VALUES<tr><th>FIELD<th>VALUE");
   
  Enumeration name=req.getAttributeNames();
  
  while(name.hasMoreElements())
  {
   String hname = (String)name.nextElement();
   out.println("<tr><td>"+hname);
   out.println("<td>"+req.getAttribute(hname));
  }
  out.printf("</table>");
  out.printf("</body>");
 }
}

No comments:

Post a Comment