Responding with an HTML page with the session ID in a form field

To maintain the session identity, each HTML response page can return the session ID in a form field.

The most usual way to do this is to have the JSP insert all the required fields, including the session identifier, into the HTML page. Add the following scriptlet code on the JSP page.

<%= utb.getRequiredHtmlFields() %>

Alternatively, you can use the portlet JSPTags, which use the JspContextServices interface internally with the same purpose.

As a third way, perform the following steps to respond with only the session ID in a form field:

  1. Obtain the operation context from the request object when a request from the HTML client is received by the request handler.
  2. Get the session ID from the operation context.
  3. Insert the session ID into the hidden session_Id field on the HTML page that is returned in response to the request.

For example, in a JSP file, use the following sample code to insert the hidden session ID field on the HTML page:

<jsp:useBean id="utb" scope="page" 
             class=" com.ibm.btt.portal.base.PortletJspContextServices "/>
<%
String dse_sessionId = (String)utb.getSessionId;
out.println ("<input type=hidden name=sessionId value=\""+dse_sessionId+"\">");
%>