Services | Updates | Contact
Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML
Listing HTTP Headers
In this example we are going to list the headers of the HttpServletRequest object. This can be done very easily by using
 
Generator Tag (Control Tags) Example
In this section, we are going to describe the generator tag . The generator tag is a generic tag that is used to generat
 
More Tutorials...


    Loan Information     Struts     Open Source

Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

 
 
JSP

 
Comments
 
 

 

Working with sessions

                          

This JSP Tutorial shows you how to track the session between different JSP pages. In any web application user moves from one page to another and it becomes necessary to track the user data and objects throughout the application. JSP provide an implicit object "session", which can be use to save the data specific the particular to the user.

In this tutorial we will create an application that takes the user name from the user and then saves into the user session. We will display the saved data to the user in another page.

Here is the code of the JSP file (savenameform.jsp) that takes the input from user:

<%@ page language="java" %>
<html>
<head>
<title>Name Input Form</title>
</head>
<body>
<form method="post" action="savenametosession.jsp">
<p><b>Enter Your Name: </b><input type="text" name="username"><br>
<input type="submit" value="Submit">

</form>

</body>

 The above page prompts the user to enter his/her name. Once the user clicks on the submit button, savenametosession.jsp is called. The JSP savenametosession.jsp retrieves the user name from request attributes and saves into the user session using the function session.setAttribute("username",username);. Here is the code of savenametosession.jsp:

<%@ page language="java" %>
<%
String username=request.getParameter("username");
if(username==null) username="";

session.setAttribute("username",username);
%>

<html>
<head>
<title>Name Saved</title>
</head>
<body>
<p><a href="showsessionvalue.jsp">Next Page to view the session value</a><p>

</body>

 The above JSP saves the user name into the session object and displays a link to next pages (showsessionvalue.jsp). When user clicks on the "Next Page to view session value" link, the JSP page showsessionvalue.jsp displays the user name to the user. Here is the code of showsessionvalue.jsp:

<%@ page language="java" %>
<%
String username=(String) session.getAttribute("username");
if(username==null) username="";
%>
<html>
<head>
<title>Show Saved Name</title>
</head>
<body>
<p>Welcome: <%=username%><p>

</body>

The function session.getAttribute("username") is used to retrieve the user name saved in the session.

                          

Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

14 comments so far (post your own) View All Comments Latest 10 Comments:

if any one know about how to access the lotus mail inbox from jsp and using jsp how to store the password to access database with encrypted format.

Posted by manikandan on Saturday, 02.9.08 @ 16:58pm | #47696

Hi,
I am using session to get the username throught out the pages .But I want to check the same when each page loads .I tried using if condition but its not working.This is important since there are two kind of users in my application and one shouldn't get another seesion

Posted by Thomas on Wednesday, 01.9.08 @ 15:09pm | #44844

jsp session meaning

Posted by mahe on Thursday, 01.3.08 @ 15:52pm | #44431

hello all of you

Posted by mukesh on Wednesday, 01.2.08 @ 23:49pm | #44388

how to send a list of random nos stored in an array through a session??plz help me..

Posted by souvik on Thursday, 11.15.07 @ 23:22pm | #37521

sir how can we manage session in JSP and how can we verify that the user is in the current session or not??????????????

Posted by Bushra Amin on Wednesday, 11.7.07 @ 16:02pm | #36296

Hi

I work with sessions and want to know how i can code te logout out of a session.I have to put it behind a button!

Can anyone help me with this?

Wim

Posted by Wim on Wednesday, 10.17.07 @ 19:21pm | #34286

any one can give the details of usebean in jsp

Posted by kumaran on Thursday, 09.6.07 @ 16:15pm | #25287

what is the difference between session.getAttribute("") and request.getAttribute(""), session.setAttribute("")& session.getAttribute("");.

Posted by Rameshkumar on Monday, 07.16.07 @ 10:21am | #21366

what is the similar code for ISSET() in PHP?

Posted by Arunika on Thursday, 04.19.07 @ 22:26pm | #14584

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.