Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Cookieless Session in Tomcat

Posted on 2008-06-17
5
Medium Priority
?
1,396 Views
Last Modified: 2013-11-24
I am using Tomcat 6.0

I am developing jsp pages for mobile devise and some of them do not support cookie. Thus I need to use cookieless session.

What I am doing now is to manually append the session id as querystring, and using session handler(a listener) to get the session by id. Is there any auto URL rewriting approach in Tomcat that we can make use of so we do not need to manually append the querystring, and manually populate the session by the session id?
If yes, how to configure it?

Thanks a lot!!
0
Comment
Question by:william007
  • 3
5 Comments
 
LVL 92

Expert Comment

by:objects
ID: 21801049
try setting cookies to false in the context definition

http://tomcat.apache.org/tomcat-6.0-doc/config/context.html

0
 
LVL 92

Expert Comment

by:objects
ID: 21801075
I read that wrong. You need to handle it yourself, an I think jstl handles it for you.

0
 
LVL 92

Assisted Solution

by:objects
objects earned 400 total points
ID: 21801088
0
 
LVL 28

Accepted Solution

by:
rrz earned 1600 total points
ID: 21802771
If you are not using JSTL as suggested by objects, then you could use the encodeURL method.    
Here is a page that demonstrates the method.  Use the encoded url to increase the hit count when cookies are not used.  
<%
  String url = request.getRequestURL().toString();
  String encoded = response.encodeURL(url);
  Integer count = (Integer)session.getAttribute("count");
  if(count==null)count = new Integer(0);
  session.setAttribute("count",new Integer(count.intValue() + 1));
%>
sessionId=<%=session.getId()%><br/>
isNew=<%=session.isNew()%><br/>
fromURL=<%=request.isRequestedSessionIdFromURL()%><br/>
fromCookie=<%=request.isRequestedSessionIdFromCookie()%><br/>
url=<%=url%><br/>
encoded=<%=encoded%><br/>
<a href="<%=url%>">Not encoded request</a><br/>
<a href="<%=encoded%>">Encoded request</a><br/>
count=<%=count%>   <br/>
0
 
LVL 9

Author Comment

by:william007
ID: 21836870
Thanks:)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

824 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