Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

JSP Sessions & URL Rewriting

Posted on 2001-07-19
15
2,147 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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 50 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 92

Expert Comment

by:objects
ID: 6301139
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

856 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