JAVA CODE FOR SESSION MANAGEMENT USING SERVLET-HIDDEN FORM FIELD | URDINESH

Software Programming, Tutorials, Interview Preparations,Stock Market,BSE/NSE, General informations

Tuesday, May 20, 2014

JAVA CODE FOR SESSION MANAGEMENT USING SERVLET-HIDDEN FORM FIELD


Front page using html
<html>
<head>
<title> EXAMPLE FOR SESSION:HIDDEN FORM FIELDS </title>
</head>
<form action="http://localhost:8080/servlet/Hidden1" method= "get">
<h1>WELCOME TO EBAY!!!!</h1><BR>
<H2>YOU ARE IN COMPUTER PAGE</H2>
<center> <b>SELECT THE ITEM U LIKE TO PURCHASE
<br><br>
<input type="radio" name="s1" value="V1">PEN DRIVE
<input type="radio" name="s1" value="V2">PRINTER
<input type="radio" name="s1" value="V3">WEB CAMERA
<br><br>
<Input type="submit" value="click here to next page">
</center>
</form>
<body bgcolor=PINK>
</body>
</html>

Hidden1.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class Hidden1 extends HttpServlet
  {
 public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException,IOException
 {
   res.setContentType("text/html");
   PrintWriter pw=res.getWriter();
   String item1=req.getParameter("s1");
   pw.println("<html><body>");
   pw.println("<form method=get   action=\"http://localhost:8080/servlet/Hidden2\">");
               pw.println("<h1>WELCOME TO EBAY!!!!</h1><BR>");
   pw.println("<H2>YOU ARE IN MOBILE PAGE</H2>");
  pw.println("<center> <b>SELECT THE ITEM U LIKE TO PURCHASE
  <br><br>");
  pw.println("<input type="radio" name="s2" value="V1">NOKIA ");
 pw.println("<input type="radio" name="s2" value="V2">SAMSUNG ");
 pw.println("<input type="radio" name="s2" value="V3">LG");
 pw.println("<br><br>");
 pw.println("<input name=s2 type=hidden value= "+item1+ "><br>");
 pw.println("<input name=submit type=submit value=click><br>");
 pw.println("<input name=reset type=reset value=reset ><br>");
 pw.println("</center></form>");
 pw.println("</body></html>");
 pw.close();
        }
}


Hidden2.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class Hidden2 extends HttpServlet
{
 public void doGet(HttpServletRequest req, HttpServletResponse res)throws   ServletException,IOException
  {
   res.setContentType("text/html");
   PrintWriter pw=res.getWriter();
   String n1=req.getParameter("item1");
   String n2=req.getParameter("item2");
   pw.println("<html><body bgcolor="cyan");
   pw.println("<h1> Welcome!!!!! "</h1><br><br>");
   pw.println("<h2> Dear customer, You have selected" +n1 +"and" +n2+"</h2>");
   pw.println("</body></html>");
   pw.close();
  }

}

No comments:

Post a Comment

Thanks for your valuable comments

Followers