Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session lost in Tomcat when POST is done from a remote computer

Status
Not open for further replies.

fmargueirat

Programmer
Aug 28, 2007
1
0
0
CA
I am having this weird problem with Tomcat v.5.5.20 . I have a simple JSP that sets a session attribute (session key) and has a form with a couple of text input fields and a submit button. The action of the form is another JSP and the method is post. The other JSP reads the session attribute. If I browse these JSPs locally I have no problems reading the session attribute in the second JSP. But if I do it from another computer, the seconds JSP gets a null value for the attribute. It looks like the session has been lost. Any ideas of what I am doing wrong or if there is any setting missing in Tomcat? Here's the code for the JSPs.

test1.jsp

Code:
<%@page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<%
  session.setAttribute("session_key", "ABDCEF0123456789");
%>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Set session attribute</title>
  </head>
  <body>
    <a href="./test2.jsp">Click here</a>>
    <form action="./test2.jsp" method="post">
      Enter your personal information<br>
      First Name <input name="fname" type="text" size="20"><br>
      Last Name <input name="lname" type="text" size="20"><br>
      <input type="submit" value="Go!">
    </form>
  </body>
</html>

test2.jsp

Code:
<%@page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Get session attribute</title>
  </head>
  <body>
    Your name is <%= request.getParameter("fname") %> <%= request.getParameter("lname") %>.<br>
    The session key is <%= (String) session.getAttribute("session_key") %>
  </body>
</html>

Thanks

Fernando
 
Hi

Maybe that remote machine has something that blocks cookies. Or your machine has something that blocks cookies from remote machines. Are you sure the cookie containing the session id arrives to Tomcat ?

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top