Solved

Got value of session variable in next page without encodeURL

Posted on 2002-03-12
11
177 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
[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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

717 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