fmargueirat
Programmer
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
test2.jsp
Thanks
Fernando
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