my dog learned polymorphism
The moose likes Servlets and the fly likes Problem with session tracking Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem with session tracking" Watch "Problem with session tracking" New topic

Problem with session tracking

Vani Kadur

Joined: Oct 02, 2000
Posts: 19
I am having trouble with session tracking in servlet/JSP pages. I have a form in my JSP page the action for which is handled by the servlet MyServlet. Here is the code snippet:
<%@ page session="true" %>
<form name="myForm"
Your Session ID: <%=session.getId() %>
When I open this page in the browser, it prints the session ID. I am trying to access the session object from MyServlet and it is coming out to be null and the following code prints :
"Session is null"
public void doPost(HttpServletRequest request,
HttpServletResponse response )
throws IOException, ServletException {
HttpSession session = request.getSession(false);

if(session == null) {
System.out.println("Session is null");
I don't want to create a new session in the servlet but want to use the HttpSession(session) created by the JSP page.
Any help is greatly appreciated.

[This message has been edited by Vani Kadur (edited May 24, 2001).]

Vani Kadur<br />==========<br />SCJP(98%)<br />SCWCD(85%)<br />IBM Certified Developer - XML and Related Technologies.
I agree. Here's the link:
subject: Problem with session tracking
It's not a secret anymore!