• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session

 
Kieth Lyman
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scenario:
We have an inhouse application(http://www.a.com) that 'posts' to a different java application's servlet (http://www.b.com/GetAppServlet?token=1234)
In this servlet, I store a parameter sent over into the session.
I display a jsp page (At this time the session is still the same as prior)
Click a button, posts to another servlet (http://www.b.com/SetAppServlet?...) in the same application.... this is creating a new session.


why?
 
Pravin Shirke
Ranch Hand
Posts: 152
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kieth,
Please post some code snippets for the same. i think you are creating a new session in your another servlet. please check.

 
Kieth Lyman
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pravin,

First Servlet:
HttpSession session = request.getSession( true);
session.setAttribute("x", request.getParameter("x"));

Render jsp page:
...servletcontext.getRequestDispatcher(page.jsp.forward(req,res);

JSP:
<a href="/SetServlet?a=1&b=2"

SetServlet:
HttpSession session = request.getSession(true);
session.getAttribute("x") - THIS IS NULL BECAUSE IT'S A DIFF SESSION (VERIFIED BY DISPLAYING SESSIONID)
 
Kieth Lyman
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would it matter if this first application 'a' does a 'response.sendRedirect' vs setting the action of a form and submitting that form
'
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64720
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kieth Lyman wrote:Would it matter if this first application 'a' does a 'response.sendRedirect' vs setting the action of a form and submitting that form

No. They are identical.
 
Shefali Naik
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kieth Lyman wrote:Hi Pravin,

First Servlet:
HttpSession session = request.getSession( true);
session.setAttribute("x", request.getParameter("x"));

Render jsp page:
...servletcontext.getRequestDispatcher(page.jsp.forward(req,res);

JSP:
<a href="/SetServlet?a=1&b=2"

SetServlet:
HttpSession session = request.getSession(true);
session.getAttribute("x") - THIS IS NULL BECAUSE IT'S A DIFF SESSION (VERIFIED BY DISPLAYING SESSIONID)




If I am not mistaken, <a href> tag will not forward the session related data that you created in the previous jsp. Try using c:url JSTL tag instead.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64720
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shefali Naik wrote:If I am not mistake....

You are mistaken. An anchor link will have no affect on sessions within the same web applications. And, of course, sessions aren't shared across web applications. The use of <c:url> or not is irrelevant.
 
Kieth Lyman
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
response.sendRedirect created a new session on the second webapp from the first servlet...that did work. This is different than the 'submit'.
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kieth Lyman wrote:response.sendRedirect created a new session on the second webapp from the first servlet...that did work. This is different than the 'submit'.
Hum... I was checking the API and there is nothing about it. They don't metion a new session: http://download.oracle.com/javaee/1.4/api/javax/servlet/http/HttpServletResponse.html#sendRedirect%28java.lang.String%29
Do you have any link about it?

I was thinking and maybe it's because the redirect method it's sending the user to another JVM.
 
Kieth Lyman
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear, did you mean 'context' is not shared between apps.
Session should not be a problem as it is based on the session id of the client which is passed in a cookie in the request.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, he meant session. (Which is a context, btw.)

Passing a session ID from one webapp into another doesn't mean they're sharing sessions.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64720
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't share sessions between web apps. Period.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic