Given a scenario, describe which session management mechanism the Web container could employ, how cookies might be used to manage sessions, how URL rewriting might be used to manage sessions, and write servlet code to perform URL rewriting.

The following approaches are using for tracking a user's sessions:

package javax.servlet.http;

public interface HttpServletRequest extends javax.servlet.ServletRequest {
	...
	public boolean isRequestedSessionIdFromCookie();
	public boolean isRequestedSessionIdFromURL();
	public boolean isRequestedSessionIdValid();
}
					

There are 2 methods in the HttpServletResponse for URL rewriting:

package javax.servlet.http;
					
public interface HttpServletResponse extends javax.servlet.ServletResponse {

	public java.lang.String encodeURL(java.lang.String url);
	public java.lang.String encodeRedirectURL(java.lang.String url)

}
					

public void doGet(HttpServletRequest req, HttpServletResponse res)
		throws IOException, ServletException {

	response.setContentType("text/html");
	PrintWriter out = response.getWriter();
	...
	out.print("<form action='");
	out.print(response.encodeURL("SessionExample"));
	out.print("' ");
	out.println("method='post'>");
}

					

Professional hosting     Belorussian informational portal         Free SCBCD 1.3 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     Free IBM Certified Associate Developer Study Guide     Free SCJP 5.0 (Tiger) Study Guide     Free Mock Exam Engine     IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide