Bookmark Topic Watch Topic
  • New Topic

Session Tracking in websphere.

 
Gurumurthy Ramamurthy
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Report post to moderator
Guys:

This is my servlet program:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class SimpleCounter extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/plain");
HttpSession session = req.getSession(true);
String sessionId=session.getId();
Integer count = (Integer) session.getValue("sessiontest.counter");
if (count==null)
count = new Integer(1);
else
count = new Integer(count.intValue() + 1);
PrintWriter out = res.getWriter();
session.putValue("sessiontest.counter", count);
out.println("Counter value..."+count);
out.println("Session id..."+sessionId);
}
}

1. If I invoke the servlet, the counter says "1" and some session id. eg. http://localhost:9080/SimpleCounter/ (refresh 2,3 times so that the counter says "4"
2. If I open another browser and type the URL and append the session id eg. http://localhost:9080/SimpleCounter/;jsessionid=x7ccjxzkjkxc78dkdd-NG, the expected behaviour is that the counter should say "5" because of the same session, but the counter value says "1" and the new session id is created.

Can you pls. let me know is there anything I need to do for this URL rewriting type of session tracking on websphere?

Thanks,
Guru
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Report post to moderator

Can you pls. let me know is there anything I need to do for this URL rewriting type of session tracking on websphere?


Session tracking is automatic. The job of sticking the jsessionid cookie at the end of the url is done by the container. All you have to do is use encodeURL() method of HttpServletResponse.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!