2

I come back with the same question but this time more documented. i have a web application with many servlets and JSPs. The application has a LogIn option. In the LogIn servlet i start a new session, and after placing some informations in the session i go forward to a JSP.

LogIn.java relevant code:

HttpSession sess = request.getSession(true); sess.setAttribute("GLN", user); rd.forward(request, response); 

After I forward, I get a Jsp page called Insert.jsp where I get the sessions attributes.

Insert.jsp relevant code:

HttpSession sess = request.getSession(false); if (sess != null){ out.println(sess.getAttribute("GLN")); } 

After this i have a form that directs me to a servlet Adaugare.java. Here i do the same thing:

Adaugare.java code:

HttpSession sess = request.getSession(false); 

Here comes the problem. Later edit: This returns null, as no session exists. Then i forward to same Insert.jsp file and there, even if i have HttpSession sess = request.getSession(false);, a new session with a new session ID is created different from the first one. So obviously out.println(sess.getAttribute("GLN")); returns null.

This is the long story. The short version:

When i go from a servlet to a jsp, session is ok, when i go from a jsp to a servlet, session is nowhere to be found . Then a new session is created when i forward to a JSP. Practically it creates a new cookie. If i print the contextPath from JSP and serlet, it's the same.

But here is the strange thing. This happens when i run the application on a apache with a mod_jk. When i run the app from a tomcat, it works fine.......

Please help, i've been stuck for 2 weeks on this problem.

Answer to dan: (Text to long for comment and need to wait 7 hours to reply my own question) I deleted all comented lines. Hope that is ok. I'm not the one in charge with the server, but the one who is told me it's not multiple workers.

worker.list=jk-status worker.jk-status.type=status worker.jk-status.read_only=true worker.list=jk-manager worker.jk-manager.type=status worker.list=balancer worker.balancer.type=lb worker.balancer.error_escalation_time=0 worker.balancer.max_reply_timeouts=10 worker.balancer.balance_workers=node1 worker.node1.reference=worker.template worker.node1.host=localhost worker.node1.port=8109 worker.node1.activation=A worker.balancer.balance_workers=node2 worker.node2.reference=worker.template worker.node2.host=localhost worker.node2.port=8209 worker.node2.activation=A worker.template.type=ajp13 worker.template.socket_connect_timeout=5000 worker.template.socket_keepalive=true worker.template.ping_mode=A worker.template.ping_timeout=10000 worker.template.connection_pool_minsize=0 worker.template.connection_pool_timeout=600 worker.template.reply_timeout=300000 worker.template.recovery_options=3 
4
  • 1
    Are you using multiple workers, behind mod_jk? Commented Oct 8, 2012 at 11:19
  • No multiple workers. I bet it's something from the cookies creation, but i can't find what. Commented Oct 8, 2012 at 11:33
  • HTTPS in Login and not otherwise? Commented Oct 8, 2012 at 12:19
  • Sorry T J, i don't understand the question...The code is copy-paste from files. Commented Oct 8, 2012 at 12:41

1 Answer 1

1

If the requests are balanced between multiple workers you should set the session stickiness flag to true. See: http://tomcat.apache.org/connectors-doc/reference/workers.html for more details. You should try:

worker.balancer.sticky_session=True 
Sign up to request clarification or add additional context in comments.

6 Comments

I edited the question. Can't reply here or reply my own question. Thanks for helping
From your config you are using a balancer and multiple nodes (workers). Like advised in my answer, please try and set the session stickiness.
I don't have server permission to change file. But the server administrator assured me it's not load balancing. workers.tomcat_home=/opt/tomcat workers.java_home=/opt/jdk ps=/ worker.list=worker1 worker.worker1.port=8009 worker.worker1.host=localhost worker.worker1.type=ajp13 worker.worker1.retries=4 worker.worker1.reply_timeout=300000 worker.worker1.max_reply_timeouts=4 worker.worker1.connection_pool_timeout=60 worker.worker1.ping_mode=A worker.worker1.socket_connect_timeout=10
See section "Load Balancing Directives" from my link. In our case the difference is that you are configuring the workers (nodes) using two separate worker.balancer.balance_workers entries, normally that should look like: worker.balancer.balance_workers = node1, node2.
So you say that my server admin is wrong and i use loadbalancing? So i need to put the worker.balancer.sticky_session=True in workers.properties? Sorry, I don't really know what load_balancing does, that's why i ask stupid questions
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.