PDA

View Full Version : Apache RewriteEngine and Java HTTPSession


myszka
06-05-2009, 08:28 AM
I am have some problems with java httpsession after I starting to use the RewriteEngine. since I turned it on the code is creating a new session each time instead of using the previously created one. I am sure some one must have used this before and got it working, can you have a look at the simple sample I created and let me know what I need to change.

thanks.

web.xml
---------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>SessionTest</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>page</servlet-name>
<jsp-file>/Page.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>page</servlet-name>
<url-pattern>/page</url-pattern>
</servlet-mapping>
</web-app>
---------------------------------


Page.jsp
---------------------------------
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><%=request.getSession().getId()%>+" -- Insert title here"</title>
</head>
<body>
<a href="/page">Page</a>
</body>
</html>
--------------------------------



worker.properties
--------------------------------
workers.tomcat_home=/home/user/apache-tomcat-6.0.18
workers.java_home=/home/user/jvm/jdk1.6.0_07
ps=/
worker.list=app1_worker,st_worker

worker.app1_worker.port=8009
worker.app1_worker.host=localhost
worker.app1_worker.type=ajp13
worker.app1_worker.lbfactor=1

worker.st_worker.port=8009
worker.st_worker.host=localhost
worker.st_worker.type=ajp13
worker.st_worker.lbfactor=1
--------------------------------


apache VirtualHost
--------------------------------

<VirtualHost 192.168.1.156:80>
DocumentRoot /home/user/tomcat6/webapps/SessionTest
ServerName www.stest.p100
JkMount /* st_worker
RewriteEngine On
RewriteRule /(.*) /SessionTest/$1 [PT]
</VirtualHost>
--------------------------------

schleppel
06-06-2009, 09:28 PM
Is the cookie's path being set to /SessionTest/?
What are the headers sent and received by the browser?

myszka
07-13-2009, 09:01 AM
request.getCookies() is returning null. for just the session.

request.getContextPath /SessionTest
request.getRequestURI() /SessionTest/page
request.getRequestURL() http://www.stest.p100/SessionTest/page


if I create cookie by hand it shows on the jsp page. getCookies finds it.
Cookie userCookie = new Cookie("user", "uid1234");
((HttpServletResponse) response).addCookie(userCookie);

Adding in ask to set cookies in the browser the Session path is /SessionTest, and the hand make cookies path is /

So how do I get the HttpSession to not add the /SessionTest?