Java Reference
In-Depth Information
out.println("</STYLE>");
out.println("</HEAD>");
out.println("<BODY>");
out.println("<BR><BR><BR>");
out.println("<CENTER>" + message + "</CENTER>");
out.println("</BODY>");
out.println("</HTML>");
out.fl ush();
}
}
Note the addition of cookie values to the current session (making use of the
Cookie class's getName and getValue methods). If this is the user's fi rst visit to the
site (indicated by a null value for session variable fi rstVisit ), then the user is redi-
rected to the GetPreferences servlet. Since the GetPreferences servlet is not receiv-
ing form data, it implements the doGet method…
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.WebServlet;
@WebServlet("/GetPreferences")
public class GetPreferences extends HttpServlet
{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException,ServletException
{
response.setContentType("text/HTML");
HttpSession adderSession = request.getSession();
adderSession.putValue("fi rstVisit","Yes");
PrintWriter out = response.getWriter();
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>Preferences</TITLE>");
out.println("</STYLE>");
out.println("</HEAD>");
out.println("<BODY>");
out.println("<BR><BR><BR>");
out.println("<CENTER>");
out.println(
"<FORM METHOD=POST ACTION='ShowSum'>");
out.println("<FONT COLOR='Blue' SIZE=5>"
Search WWH ::




Custom Search