Solved

Got value of session variable in next page without encodeURL

Posted on 2002-03-12
11
173 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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
 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xjc and jaxb 2 91
SimpleDateFormat.parse examples 19 92
nested if has else if 13 94
Is it possible to "sandbox" html content within a JSP? 4 101
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
When we purchase storage, we typically are advertised storage of 500GB, 1TB, 2TB and so on. However, when you actually install it into your computer, your 500GB HDD will actually show up as 465GB. Why? It has to do with the way people and computers…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

813 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

10 Experts available now in Live!

Get 1:1 Help Now