Elena Palanca wrote:
> Hi,
> I would like to know in which way using JSP is easier (compared to
> Servlets) to maintain the session state of a user.
> Thanks
> Elena
Well, JSP pages use exactly the same internal techniques as servlets do
(with either cookies or URL rewriting), so I cannot see how one approach
is easier than the other.
In a JSP page, you reference session-related beans like this:
<jsp:useBean id="theBean" scope="session" class="MyClass" />
where you can retrieve the same bean in a servlet like this:
HttpSession session = request.getSession();
MyClass theBean = (MyClass) session.getValue("theBean");
With both servlets and JSP pages, you need to use the
response.encodeURL() method around any hyperlinks you generate, in case
the client's browser does not have cookies enabled.
In a JSP page, you might do this:
Go to the <a href="<%= response.encodeURL("menu.jsp") %>">Main
Menu</a>
where a similar link generated by a servlet might look like this:
PrintWriter writer = response.getWriter();
writer.println("Go to the <a href=\"" +
response.encodeURL("menu.jsp") +
"\">Main Menu</a>");
So the two technologies are very similar in how they approach session
state maintenance.
Craig McClanahan
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JSP-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".