File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Servlet sessions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet sessions" Watch "Servlet sessions" New topic

Servlet sessions

Lou Pelagalli
Ranch Hand

Joined: Nov 11, 2003
Posts: 150

I'm following a tutorial I found and I'm having difficulty saving session information.

Here's the rundown, my code follows my signature.
Gets the parameters, displays them, and saves them in the session.
Click on "Click here for target"

Displays the session information saved in simpleweb/ParamServlet.

TargetServlet behaves as though there is no Session information, just displays this
Information in the session:

Session Exists!

Name: org.apache.catalina.ASYNC_SUPPORTED, Value: null

All servlets appear to link fine so I don't think the problem is in web.xml. I remember to stop and restart Tomcat with each change.

Apache Tomcat 7.0.5 Server
javac -version = "javac 1.6.0_23"

Any help you provide would be greatly appreciated!



Here's the code


Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 662

why this code is there in TargetServlet, it doesn't getany request attributes/parameters i guess, from what i see.. so subsequently, control doesn't go inside the while loop..
Abhay Agarwal
Ranch Hand

Joined: Feb 29, 2008
Posts: 1341

When you are invoking Target Servlet, there are no parameters in request. All parameters are present in HTTPSession. So get your parameters from session ( not from request)

Just replace


in Target Servlet doGet() and you will get your desired result as shown below.

Information in the session:

Session Exists!

Name: Param2, Value: Hello
Name: param1, Value: World

~ abhay

Oracle certified Java 8 Programmer I (1Z0-808), Oracle Java Web Service Developer (1z0-897), Oracle certified Java 7 Programmer, SCJA 1.0, SCJP 5.0, SCWCD 5.0, Oracle SQL Fundamentals I, CIW Certified Ecommerce specialist
Lou Pelagalli
Ranch Hand

Joined: Nov 11, 2003
Posts: 150
Thank you Abhay!

That was the problem. I copied ParamServlet as TargetServlet and made modifications, but I missed that one.

Spent a long time looking for it. I think the difference between Request and Session is burnt into memory now, and I'll quickly know what to look for (hopefully) if I see this again!
I agree. Here's the link:
subject: Servlet sessions
It's not a secret anymore!