JSP Example for Session Implicit Object

JSP Example  for Session Implicit Object 

index.html
<html> 
<head>
<title>Welcome Page: Enter your name</title>
</head>
<body> 
<form action="session.jsp"> 
<input type="text" name="inputname"> 
<input type="submit" value="click here!!"><br/> 
</form> 
</body> 
</html>
The session.jsp page displays the name which user has entered on the index page and it stores the same variable in the session object so that it can be fetched on any page until the session becomes inactive.
session.jsp
<html> 
<head>
<title>Passing the input value to a session variable</title>
</head>
<body> 
<% 
String uname=request.getParameter("inputname"); 
out.print("Welcome "+ uname);
session.setAttribute("sessname",uname); 
%> 
<a href="output.jsp">Check Output Page Here </a>
</body> 
</html>
In this page, we are fetching the variable’s value from session object and displaying it.
output.jsp
<html> 
<head>
<title>Output page: Fetching the value from session</title>
</head>
<body> 
<% 
String name=(String)session.getAttribute("sessname"); 
out.print("Hello User: You have entered the name: "+name); 
%> 
</body> 
</html>

Comments

Popular posts from this blog

Artificial Intelligence

The taxonomy of CASE Tools

Zoho Second round - adding a digit to all the digits of a number