Solved

Got value of session variable in next page without encodeURL

Posted on 2002-03-12
11
167 Views
Last Modified: 2010-04-01
I havemy OS linux,tomcat 3.2.3 web server. I have intialize a session variable in one jsp page and bellow it I'm getting the value of that session variable in the same page but in next jsp page I'm not not getting the value og that session value.Pls help how can get the the value without writting response.encodeURL?
0
Comment
Question by:alak
  • 5
  • 5
11 Comments
 
LVL 19

Expert Comment

by:cheekycj
Comment Utility
can you post some the code you have for both JSPs?

CJ
0
 
LVL 6

Expert Comment

by:kotan
Comment Utility
Did you set the session attribute of page directive to false on the next page, like below?
  <%@ page session="false" %>

Set the false to the session attribute force that page to create new session instead of using existing one.

Try to set it to true.
0
 

Author Comment

by:alak
Comment Utility
my first page is StartPage.jsp as bellow :
<%@ page session="true" %>
 <%
 // first we will put some test data into the bean to show
 // we can get it back out again in another page!
 String ls_validate = "This is our original session";
 session.setAttribute("Validate", ls_validate);

 // Now we will build a string containing the URL for the next page.
 // We are encoding session information into the URL string, so as you
 // move from page to page, your the Container will know what session
 // has been used. Without this information, the container will
 // start a new session for each page request.
 String ls_session_id = session.getId();
 String ls_encode_url = response.encodeURL("NewPage.jsp");
 String ls_normal_url = "NewPage.jsp";
 %>

 <Html>
 <Head>
 </Head>
 <Body>
 Sample URL with encoded information: <%= ls_encode_url %> <BR>
 Our Session id is : <%= ls_session_id %><BR><BR>

<a href='<%= ls_encode_url %>'> Move to new page and keep session alive</a><BR><BR>
<a href= '<%= ls_normal_url %>'> Move to new page without encoding the URL</a>
 </Body>
</Html>
 
Next page is as follows:

<Html>
<Head>
</Head>
<Body>
 <%@ page session="true" %>
  The Current Session id is: <%= session.getId() %>


 Checking the value stored in our validate attribute:
<%=session.getAttribute("Validate")%>
 </Body>
</Html>

In the above example I'm not getting value without encodeURL.
0
 

Author Comment

by:alak
Comment Utility
Is there need to change the settings of Tomcat for getting session variable value in next page. I can't understand why it showing the value is null?
0
 
LVL 6

Expert Comment

by:kotan
Comment Utility
This may cause by the the cookies of the browser have been disable.

response.encodeURL() will add session id parameter to url if the browser doesn't support cookies. Otherwise, the url remain the same.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 6

Expert Comment

by:kotan
Comment Utility
Actualy, the web server have store a session id into browser cookies in order to make a session available. If the browser disable the cookies, then you can use the session anymore. The good pratice is using encodeURL, it will include the session id in the url if no cookies available.
0
 
LVL 6

Accepted Solution

by:
kotan earned 100 total points
Comment Utility
>If the browser disable the cookies, then you can use the session anymore.

I mean:
  then you can't use the session anymore.
0
 

Author Comment

by:alak
Comment Utility
My web browser have the setting of cookies enabled. Still it dose not give the session varible value.
0
 
LVL 6

Expert Comment

by:kotan
Comment Utility
What type of browser, os, tomcat version?
0
 

Author Comment

by:alak
Comment Utility
When I change the settings of my browser (Konqueror)
1> enable cookies
2>Accept cookies by defalt

Then I got the value of the session variable.
Thank you very much for your kind help.
0
 

Author Comment

by:alak
Comment Utility
When I change the settings of my browser (Konqueror)
1> enable cookies
2>Accept cookies by defalt

Then I got the value of the session variable.
Thank you very much for your kind help.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
In this step by step tutorial with screenshots, we will show you HOW TO: Enable SSH Remote Access on a VMware vSphere Hypervisor 6.5 (ESXi 6.5). This is important if you need to enable SSH remote access for additional troubleshooting of the ESXi hos…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now