Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Got value of session variable in next page without encodeURL

Posted on 2002-03-12
11
Medium Priority
?
179 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
Independent Software Vendors: 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 300 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

With so many activities to perform, Exchange administrators are always busy in organizations. If everything, including Exchange Servers, Outlook clients, and Office 365 accounts work without any issues, they can sit and relax. But unfortunately, it…
Let's take a look into the basics of ransomware—how it spreads, how it can hurt us, and why a disaster recovery plan is important.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

604 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