Java Reference
In-Depth Information
+ "User Preferences</FONT>");
out.println("<BR>");
out.println("<TABLE>");
out.println("<TR>");
out.println("<TD>First name</TD>");
out.println("<TD><INPUT TYPE='Text' "
+ "NAME='Name' VALUE='' SIZE=15></TD>");
out.println("</TR>");
out.println("<TR>");
out.println("<TD>Foreground colour</TD>");
out.println("<TD><INPUT TYPE='Text' "
+ "NAME='ForeColour' VALUE=''"
+ "SIZE=10></TD>");
out.println("</TR>");
out.println("<TR>");
out.println("<TD>Background colour</TD>");
out.println("<TD><INPUT TYPE='Text' "
+ "NAME='BackColour' VALUE=''"
+ "SIZE=10></TD>");
out.println("</TR>");
out.println("</TABLE>");
out.println("<BR><BR>");
out.println("<INPUT TYPE='Submit' "
+ "VALUE = 'Submit'>");
out.println("<INPUT TYPE='Reset' "
+ "VALUE='Clear'>");
out.println("</CENTER>");
out.println("</BODY>");
out.println("</HTML>");
out.fl ush();
}
}
Note the setting of session variable
fi rstVisit
to 'Yes', for subsequent checking by
the
ShowSum
servlet. Figure
8.10
shows the output generated by the
GetPreferences
servlet and some example user entry:
Servlet
ShowSum
may be called from either
GetPreferences
or
CookieAdder
. Since
the former passes on form data and the latter doesn't,
ShowSum
implements neither
doPost
nor
doGet
, but method
service
. Before attempting to transmit the result page,
the servlet checks the value of session variable
fi rstVisit
. If this variable has been set
to 'Yes', the servlet retrieves the user's preferences (via the
HttpServletRequest
object), creates the appropriate cookies and updates the session variables (including
the setting of the
fi rstVisit
cookie variable and session variable to 'No').
Search WWH ::
Custom Search