• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP Compiling and session issue

 
Dharmesh Shah
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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
 
Dave Soto
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • 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
  • 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.
<%}
} %>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic