Testing browsers for a session variable

The autoRedirect snippet in the JSP drawer of the Snippets view tests for the presence of a session variable. If the session variable is not present, the customized code forwards control to a different Web page.

The snippet must be placed within the <head> tag of a JSP page after the <pageEncoding> tag. To insert and configure this snippet, follow these directions:

  1. From the JSP drawer of the Snippets view, add the snippet to the <head> tag of the page after the <pageEncoding> tag. For more information, see Inserting code snippets into EGL and JSP files. The Insert Template window opens.
  2. In the Insert Template window, set SessionAttribute to the name of the session variable that is being tested. The default value is UserID.
  3. Set ApplicationName to the name of your project or application. The default value is EGLWeb.
  4. Set PageName to the name of the page that the browser will be redirected to if the session variable is absent. The default value is Login.jsp.
  5. When you have customized the values in the Insert Template window, click Insert.
The code inserted by this snippet is as follows:
<%
if ((session.getAttribute("userID") == null ))
  {
   String redirectURL = 
   "http://localhost:9080/EGLWeb/faces/Login.jsp";
   response.sendRedirect(redirectURL);
  }
%>

Related tasks
Inserting code snippets into EGL and JSP files

Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.