[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

JSP Sessions & URL Rewriting

Posted on 2001-07-19
15
Medium Priority
?
2,339 Views
Last Modified: 2013-11-24
I am running Tomcat on top of Apache. An HTTP request for a URL that has 'CSP' is passed by Apache to Tomcat. This works fine for http://localhost/CSP/Test.jsp. Now I want to add sessions to my JSP pages. As an experiment, I disabled cookies on my browser, and I have
Test.jsp rewritten as follows:

<html>
<body>
<a href="<%= response.encodeURL("/CSP/Test.jsp") %>">Test</a>
</body>
</html>

Because cookies are disabled, URL rewriting is used, and the anchor becomes:
http://localhost/CSP/Test.jsp;jsessionid=2ygm1jiad1

According to the JSP specifications, the session information is encoded and assigned to 'jsessionid', and this is appended to the URL following a semi-colon. However, when I click on the link above, Apache returned 404 Not Found. It seems that the semi-colon and extra string at the end of the URL has made it an invalid URL. Apache did not even pass the request to Tomcat even though the URL contains 'CSP'.

On this EE website, I noticed that with URL rewriting, the 'jsessionid' is appended following a question mark, not a semi-colon. How do I make my JSP page work?
0
Comment
Question by:yongsing
  • 10
  • 5
15 Comments
 
LVL 92

Expert Comment

by:objects
ID: 6300792
> this is appended to the URL following a semi-colon

DO you have a (online) reference where you read this?
That certainly looks like an invalid url to me, should be a ?.
0
 
LVL 9

Author Comment

by:yongsing
ID: 6300838
Actually, I read that in the Java Servlet Specification v2.2, section 7.1.1 (page 35):

===================================================================
7.1.1 URL Rewriting
URL rewriting is the lowest common denominator of session tracking. In cases where a client will not accept a cookie, URL rewriting may be used by the server to establish session tracking. URL rewriting involves adding data to the URL path that can be interpreted by the container on the next request to associate the request with a session. The session id must be encoded as a path parameter in the resulting URL string. The name of the parameter must be jsessionid. Here is an example of a URL containing encoded path information:

http://www.myserver.com/catalog/index.html;jsessionid=1234

===================================================================

You can obtain the specification at:
http://java.sun.com/products/servlet/download.html#specs

I tried this http://localhost/index.html;jsessionid=1234 , but Apache returned 404 Not Found.
0
 
LVL 92

Expert Comment

by:objects
ID: 6300891
Thanks for that, will have a read.

So what's writing the ';' ?

Have you tried with '?' ?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 9

Author Comment

by:yongsing
ID: 6300914
I can't control the ';'. The following code:

response.encodeURL("/CSP/Test.jsp");

will translate into the absolute URL:

http://localhost/CSP/Test.jsp;jsessionid=2ygm1jiad1

The semi-colon is added by encodeURL(). I don't know why it doesn't add '?' instead.


Perhaps the developers of this EE site can answer my question, since they use Apache, Tomcat and JSP.
0
 
LVL 92

Expert Comment

by:objects
ID: 6300926
The ; is used in the meta tag, not in the href tag.
Will see what else I can find.

What version of Tomcat are you using?


0
 
LVL 92

Accepted Solution

by:
objects earned 200 total points
ID: 6300940
You need to modify your apache configuration:

http://www.jguru.com/faq/view.jsp?EID=53878
0
 
LVL 9

Author Comment

by:yongsing
ID: 6301102
I am using Apache 1.3.14, and Tomcat 3.2.1. I added the following to the Apache configuration file, httpd.conf:

<IfModule mod_rewrite.c>
  RewriteEngine     on
  # Force URLs with a jsessionid to go to Tomcat. Necessary because
  # Apache doesn't recognise that the semi-colon is special.
  RewriteRule       ^(/.*;jsessionid=.*)$   $1 [T=jserv-servlet]
</IfModule>

After rebooting the system, it still doesn't work. I am not sure if there is any error in the above lines.
0
 
LVL 92

Expert Comment

by:objects
ID: 6301114
Is it getting to Tomcat yet?
Are you using jserv?

0
 
LVL 92

Expert Comment

by:objects
ID: 6301128
Try asking on the Apache topic.
The problem definitely seems to be Apache not understanding the ;, so it doesn't pass it on to tomcat.
The Apache experts probably know all about this one.
0
 
LVL 92

Expert Comment

by:objects
ID: 6301134
Actually I'll ask on your behalf, I've got some spare points :)
0
 
LVL 9

Author Comment

by:yongsing
ID: 6301233
Thanks for the help, objects.
0
 
LVL 92

Expert Comment

by:objects
ID: 6301257
No worries :)
0
 
LVL 9

Author Comment

by:yongsing
ID: 6301376
I also need to uncomment the below line in the httpd.conf file, in order to use the functionality of a module.

LoadModule rewrite_module modules/ApacheModuleRewrite.dll

objects, thanks for your help. BTW, you can delete away the question in the Apache area, to reclaim back your question points.
0
 
LVL 92

Expert Comment

by:objects
ID: 6301393
Thanks for the points :)
Good to hear u got it sorted.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
A solution for Fortify Path Manipulation.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month17 days, 18 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question