Solved

How to forward the session entries through href

Posted on 2008-10-30
5
374 Views
Last Modified: 2012-05-05
Hi Friends,
I'm developing a site in jsp and it passes the session and its attributes when I go to any JSP page through servlet. But when I go to one JSP page to another via href="<% response.encodeURL("my URL?someParameter=1")%>"> ,it takes me there but losses the session entries and there shows me null session.
I'm in situation where I need to use href-links to move to another JSP page. My question is how can I use RequestDispatcher or anything else in href link through which my next JSP page could get the attributes of the session and do not show the sessionAttributes as null.
0
Comment
Question by:hsperhar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 27

Expert Comment

by:rrz
ID: 22842379
It should be working. I can't explain your problem.   Please use this code to test. Are you able to increment count with or without cookies.  
<%
  String url = request.getRequestURL().toString();
  String encoded = response.encodeURL(url);
  Integer count = (Integer)session.getAttribute("count");
  if(count==null)count = new Integer(0);
  session.setAttribute("count",new Integer(count.intValue() + 1));
%>
sessionId=<%=session.getId()%><br/>
isNew=<%=session.isNew()%><br/>
fromURL=<%=request.isRequestedSessionIdFromURL()%><br/>
fromCookie=<%=request.isRequestedSessionIdFromCookie()%><br/>
url=<%=url%><br/>
encoded=<%=encoded%><br/>
<a href="<%=url%>">Not encoded request</a><br/>
<a href="<%=encoded%>">Encoded request</a><br/>
count=<%=count%>   <br/>

Open in new window

0
 

Author Comment

by:hsperhar
ID: 22850900
Thanks for reply, this didn't work. I look further into this. Let me explain the problem in more detail:
I am creating HTTP Session in servlet which redirect to one JSP page(lets call-JSP1) with the help of RequestDispatch method. After that ,even before requesting for solution, through href I am redirecting to JSP1,but this time it gets different page in its one table with the help of JSP include page tag.Lets, for instance, call this new JSP1 page as JSP2
Ok, when I check the session IDs Servlet and JSP1 shares the same session ID but JSP2 does not,why?
In JSP2, since session is new so I am not getting the user information & cannot use session to collect that. I donot want to pass hidden parameters to passon the user information. What exactly , I am doing wrong due to which JSP2 is not getting the session of JSP1?
0
 

Author Comment

by:hsperhar
ID: 22850948
I'm using response.encodeURL method to go from JSP1 to JSP2. What exact steps I can use in href so that it can pass the same session to the next page?
0
 
LVL 27

Expert Comment

by:rrz
ID: 22851031
>Ok, when I check the session IDs Servlet and JSP1 shares the same session ID but JSP2 does not,why?
JSP2 should have same session. I don't know why you are having this problem.   Please reduce your code to the minimum that demonstrates the problem  and post it here.  Maybe we will be able to debug.
0
 

Accepted Solution

by:
hsperhar earned 0 total points
ID: 24809072
Please close this old thread, as I had the solution months ago through my research. Sorry could not attend this one.
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question