tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevin Swanson <>
Subject using url rewriting for sessions
Date Thu, 19 Oct 2000 16:47:29 GMT

I've read lots of postings on this subject, but they haven't cleared up my

I have two .jsp files, one which puts values into a session object and the
other which pulls them out. If I enable cookies, this code works fine. If I
disable cookies and try to fall back to url-rewriting i run into problems. I
am running Tomcat 3.1 in standalone mode to test this, because I've read
about problems with url rewriting using apache.

With cookies disabled, everything works as long as after loading
query-nosave.jsp the first time, I go back to it using the link I generate
in displayResults-nosave.jsp which uses encodeURL.. If however, I don't use
the link and just try to reload the page clicking on an entry in recently
viewed pages or just retyping the URL, then query-nosave.jsp generates a new
session and therefore loses the data from the old session. If cookies are
enabled, new sessions are not created - it uses the same session.

maybe i don't understand url-rewriting completely. The Sun specs make it
sound like you can just use HTTPSession and not worry about the details. But
how would your browser know how to rewrite the URL in the case I mention
above where you retype the url. Also, if use the back button to go back to
the query-nosave.jsp page and then hit reload, i have the same problem of a
new session getting created.

It seems to me either something isn't working correctly or the definition of
session isn't really the same if you aren't using cookies.

Below is the source for the jsps

Thanks in advance,



<%@ page import="coreservlets.*" %>
String ram = (String)session.getValue("ram");
<head><title>Workstation Query</title></head>
session id = <%= session.getId() %>
<h3> Workstation Report Criteria </h3>
<form method="get" action=<%=
response.encodeURL("displayResults-nosave.jsp") %>>
	<select name="ram">
		<option value="32" <% HTMLStuff.selected(out, ram, "32"); %>
		<option value="64" <% HTMLStuff.selected(out, ram, "64"); %>
		<option value="128" <% HTMLStuff.selected(out, ram, "128");
%> >128
    <INPUT TYPE="submit" NAME="Next" VALUE="Submit Report">&nbsp;
    <INPUT TYPE="reset" NAME="Reset" VALUE="Reset">

<%@ page import="coreservlets.*, jdbctest.*" %>
    String ram = request.getParameter("ram");

	session.putValue("ram", ram);

	String criteria = "where ram >=" + ram;
	SQLTest sqlTest = new SQLTest(criteria);

	Vector cols = sqlTest.columnLabels;
	Vector rows = sqlTest.rows;

<head><title> Workstation Report</title></head>
<h3> Workstation Report </h3>
<h4> Number of rows: <%= rows.size() %></h4>
session id = <%= session.getId() %>
<A href=<%= response.encodeURL("query-nosave.jsp") %>>Return to query
	int i;
	int numCols = cols.size();

	for (i = 0; i < numCols; i ++) {
<TH><%= cols.get(i) %></TH>

	Vector row;
	for (i = 0; i < rows.size(); i ++) {
		row = (Vector)rows.get(i);
		for (int j = 0; j < numCols; j ++) {
<TD><%= row.get(j) %></TD>		


View raw message