PROGRAM:
FRONT PAGE USING
HTML
<html>
<head>
<title> EXAMPLE FOR SESSION:URL
</title>
</head>
<form
action="http://localhost:8080/servlet/URL1" method=
"get">
<center> YOUR WISH IS INTIMATED BY:
<select name="s1">
<input type="radio"
name="op" value="red">RED
<input type="radio"
name="op" value="blue">BLUE
<input type="radio"
name="op" value="green">GREEN
</select>
<Input type="submit"
value="submit">
</center>
</form>
<body bgcolor=cyan>
</body>
</html>
URL1.JAVA
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class Exurl extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse
res)throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
String
color=req.getParameter("s1");
pw.println("<html><body
bgcolor="+color+">");
pw.println("<FONT
COLOR=WHITE><h1> <center> ELIGIBLITY CHECKING<BR><BR>");
pw.println("<form
method=get action=\"http://localhost:8080/servlet/URL2/" +color+ "\">");
pw.println("ENTER UR NAME: <input
name=name type=text><br>");
pw.println("ENTER UR AGE: <input
name=age type=text><br>");
pw.println("<input name=submit
type=submit value=submit>");
pw.println("<input name=reset
type=reset value=reset> <br>");
pw.println("</body></html>");
pw.close();
}
}
URL2.JAVA
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class URL2 extends HttpServlet
{
public void doGet(HttpServletRequest req,
HttpServletResponse res)throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
String name=req.getParameter(name);
String age=req.getParameter(age);
int n=Integer.parseInt(age);
if(n>=18)
String str="YOU ARE ELIGIBLE TO
VOTE";
else
String str="YOU ARE NOT
ELIGIBLE TO VOTE";
String add_param=req.getPathInfo();
System.out.println("getQueryString="+add_param);
String filter=add_param.substring(1);
System.out.println("Color extracted=
"+filter);
pw.println("<html><body
bgcolor= "+filter+">");
pw.println("<h1> Welcome
"+name+" !!! </h1>");
pw.println("<h1> <font
color=blue>"+str+"</h1>");
pw.println("</body></html>");
pw.close();
}
}
No comments:
Post a Comment
Thanks for your valuable comments