setAttribute(String, object) : This method sets the value of object as string's value and you can get this value in other JSP page which is connected to this page.
getAttribute(String name) :This method is use to fetch the value of "String" which is set by you, in other JSP page, using "setAttribute()" method.
Example : Here is a set of pages that put a user's name in the session, and display it elsewhere.
Displayname.html
<HTML> <BODY> <FORM METHOD=POST ACTION="session.jsp"> What's your name? <INPUT TYPE=TEXT NAME=username SIZE=20> <P><INPUT TYPE=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></ 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 value(output)--->
