Solved

Got value of session variable in next page without encodeURL

Posted on 2002-03-12
11
169 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
ID: 6857084
can you post some the code you have for both JSPs?

CJ
0
 
LVL 6

Expert Comment

by:kotan
ID: 6859060
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
ID: 6859394
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
ID: 6859448
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
ID: 6859455
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Expert Comment

by:kotan
ID: 6859466
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
ID: 6859469
>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
ID: 6859564
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
ID: 6859634
What type of browser, os, tomcat version?
0
 

Author Comment

by:alak
ID: 6859642
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
ID: 6859643
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Run the project 5 87
report generation frameworks 1 60
difference between projection and projection list in hibernate 1 102
spring example non maven 4 82
Cloud-based technologies and services will continue to grow in popularity in 2017 thanks to the simple, scalable and cost-effective solutions they deliver. Here are three areas where cloud adoption is poised to really take off.
An analysis of the phishing scam that has been affecting Google users, along with steps to take for protection, as well as what to do if you receive one of the emails.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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

13 Experts available now in Live!

Get 1:1 Help Now