• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP session in a servlet

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Friends,
How do I access a Jsp session in a servlet. I used
HTTPRequest.getsession(), but I am not able to access the values
Expecting an reply at the earliest.
Zafer
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you use
request.getSession() ; // request is a HttpServletRequest
you will get a new empty session if one does not already exist.
Sounds like this is what is happening - try to figure out why the session created in the JSP is not being associated with the servlet.
Bill

------------------
author of:
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Zafer,
If u want to use sessions in ur jsp page, here are the few things you have to know.
In jsp, session, is an implicit object, that is it will be there by default.
When ever you are writing a jsp page include session="true" in the page tag like this.
<%@ page language="java" session="true"%>
after that when ever you want to retrieve a value from the session use the following syntax.
<%
HttpSession session=request.getSession(true);
%>
or
<%
HttpSession session=request.getSession();
%>
The benefit of using the first method is that, if there is no session exists already, it will create a new session and will continue with other pages.
But remember to add session="true" attribute in page tag.
I hope u find this info useful.
Bye.
Loke.
 
I will open the floodgates of his own worst nightmare! All in a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic