Join us on Facebook

Please wait..10 Seconds Cancel

11.29.2013

// // Leave a Comment

Create a Servlet which will display all the objects and its application. (request,response, session, application, cookie)

Servlet which will display all the objects and its application
 
package question11; 
 
import java.io.*; 
import javax.servlet.*; 
 
public class MethodsDemo extends HttpServlet  
{ 
  private static final long serialVersionUID = 1L; 
      public MethodsDemo()  
      { 
            super();   
      } 
  protected void doGet(HttpServletRequest request, HttpServletResponse response) 
throws   ServletException, IOException 
  {     
    PrintWriter out=response.getWriter(); 
    Cookie c[]=new Cookie[5]; 
     for(int i=0;i<2;i++) 
     {   c[i]=new Cookie("name"+i,"CookieValue"+i); 
       c[i].setMaxAge(Integer.MAX_VALUE); 
       response.addCookie(c[i]); 
     }      
    out.println("<html><body>"); 
    out.println("The Page contains following cookies:<br />"); 
    HttpSession s=request.getSession(); 
    for(int i=0;i<2;i++) 
     {  
       out.println("Name:"+c[i].getName()+"    
Value:+"+c[i].getValue()+"<br />"); 
     } 
    out.println("Your session ID is:"+s.getId()+"<br />"); 
    out.println("</body></html>"); 
  } 
  protected void doPost(HttpServletRequest request, HttpServletResponse response) 
throws   ServletException, IOException 
  {     
    doGet(request,response); 
  } 
} 

0 comments:

Post a Comment