This section, illustrate about 'session' attribute of page directive with help of a example. It specifies if the generated servlet can access the session or not. This directive attribute has Boolean data type. If the vale of "session" sets to "True" , then the session persist to the next page , if sets to "False" , then you can't use the session object or <jsp:useBean> element with scope="session" in JSP page. The default value of session is "True" .
EXAMPLE
Following 3 JSP pages are included in this example :
In this Example, User input their name, and redirected to "session.jsp" page , where he will have to click "Continue" hyperlink , which again redirected him to "sessionresult.jsp", which display his inputted name.
inputname.jsp
|
< HTML>< HEAD><TITLE>INPUT YOUR NAME</TITLE></HEAD>< BODY>< FORM METHOD=POST ACTION="session.jsp">What's your name? <INPUT TYPE=TEXT NAME=username SIZE=20>< P><INPUT TYPE=SUBMIT value="Submit" value="Submit"></ FORM></ BODY></ HTML>
|
session.jsp
|
<%@ page language="java" %><% String name = request.getParameter( "username" );session.setAttribute( "theName", name );%> < HTML>< HEAD><TITLE>CLICK TO CONTINUE</TITLE></HEAD>< BODY>< A HREF="sessionresult.jsp">Click to Continue</A>< BR><A HREF="inputname.jsp">Click Here to go back</A></ BODY></ HTML>
|
sessionresult.jsp
|
<%@ page language="java" session="true" %>< HTML>< HEAD><TITLE>DISPALYING YOUR NAME</TITLE></HEAD>< BODY>< font color=red size="10">Hello, <%= session.getAttribute( "theName" ) %></font></ BODY></ HTML> |
OUTPUT

After submitting :-

After clicking "Click to Continue"

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.