The Auto redirect 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:
- From the EGL drawer of the Snippets view, drag the Auto
redirect snippet to a blank line in the JSP file within
the <head> tag of the page. This snippet goes
into the code of the JSP file, not the code of the JSF Handler part.
For more information, see Inserting code snippets into EGL and
JSP files. The Insert Template window opens.
- In the Insert Template window, set the SessionAttribute variable
to the name of the session variable that is being tested. The default
value is UserID. See Storing data in the user's session.
- Set the ApplicationName variable to the name
of your project or application. The default value is EGLWeb.
- Set the PageName variable 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.
- Save the file.
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);
}
%>