out.println("Please enter your name:<BR>"); out.println("<INPUT TYPE=\"TEXT\" NAME=\"name\" " + "SIZE=\"25\"><P>");
out.println("<INPUT TYPE=\"SUBMIT\" VALUE=\"Submit\">"); out.println("</FORM>"); out.println("</BODY>"); out.println("</HTML>"); } else { String bcolor = request.getParameter("bcolor"); if (bcolor != null) { if (bcolor.equals("red")) { color = "#FF0000"; } else if (bcolor.equals("green")) { color = "#00FF00"; } else if (bcolor.equals("blue")) { color = "#0000FF"; } else { color = "FFFFFF"; }
name = request.getParameter("name"); hitCounts = new Integer(1); mySession.setAttribute("bcolor", color); mySession.setAttribute("hitCounts", hitCounts); mySession.setAttribute("name", name); } else { color = (String) mySession.getAttribute("bcolor"); name = (String) mySession.getAttribute("name"); hitCounts = (Integer) mySession.getAttribute("hitCounts"); }
mySession.setAttribute("hitCounts", new Integer(hitCounts .intValue() + 1));
out.println("<HTML>"); //html page2 out.println("<HEAD><TITLE>Color Select</TITLE></HEAD>"); out.println("<BODY BGCOLOR=\"" + color + "\">"); out.println("<H2>Hello " + name + "!</H2>"); out.println("<H3>You have requested this page " + hitCounts + "times.<BR></H3>"); out.println("<A HREF=\"ColorSession\">Reload Page</A>"); out.println("</BODY>"); out.println("</HTML>"); } } }
This servlet creates a HttpSession in order to store the user's name,preffer color and the times it has been accessed. When it is accessed for the first time ,it will create a new session and display a html page to ask the user enter his color and name. And after this it will display the information about the session.But,when i click the submit button in the page1,it only display the same page(page1),not page2! I don't know why!How can i make it do the things i want to?
Jeffrey Spaulding
Ranch Hand
Joined: Jan 15, 2004
Posts: 149
posted
0
Please enclose Code samples in [ Code ] Tags. I don't think i'll indent your code for you in order to read it.