Win a copy of Functional Design and Architecture this week in the Functional programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Servlet sessions

 
Ranch Hand
Posts: 150
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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

Here's the rundown, my code follows my signature.
http://localhost:8080/simpleweb/ParamServlet?param1=World&Param2=Hello
Gets the parameters, displays them, and saves them in the session.
Click on "Click here for target"

simpleweb/TargetServlet
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
Done


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!

Thanks,

Lou


Here's the code
ParamServlet


TargetServlet


web.xml
 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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..
 
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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



with



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
Done



~ abhay
 
Lou Pelagalli
Ranch Hand
Posts: 150
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic