This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

JSP Compiling and session issue

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Am having trouble with getting correct values from the objects retrieved from session in the JSP.
Am instantiating a user object in the login servlet and storing in session. The user object is access from the session in the JSP and then the getUserName() is called on the user.
The problem is that when the jsp page is called, it does not get the user name, but if I click refresh on the browser then it would display the user name.
if anyone has fix for this, let me know. Thanks!
PS: am using Tomcat JSP/Servlet engine
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This sounds like it's probably a simple one, but you'll need to post your code if you want us to be able to fix it.
 
Dharmesh Shah
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Attached is the JSP code i have.
I am not sure but it looks like the problems could be in Tomcat configuration, because it seems to display the same page even if I restart the server. For example if I login as user USER-A and refresh following page, it would display USER-A, now if i restart the server and login as USER-B and then call following page, it would still display USER-A until I refresh the page.
I have the default configuration for tomcat and have not made any modifications.

<% HttpSession ses = request.getSession();
if(ses != null){
user u = (user)ses.getAttribute("theUser");
if(u != null)
{ %>
<input type="hidden" name="userId" value=<%= u.getUserId() %> ><%= u.getUserId() %>
<input type="hidden" name="userName" value=<%= u.getUserName() %> ><%= u.getUserName() %>
<% }
else
{
%>
Please log in.
<%}
} %>
 
Sunglasses. AKA Coolness prosthetic. This tiny ad doesn't need shades:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic