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:
- 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.
- In the Insert Template window, set SessionAttribute to
the name of the session variable that is being tested. The default value is UserID.
- Set ApplicationName to the name of your project or application.
The default value is EGLWeb.
- 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.
- 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);
}
%>