This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Session tracking with URL rewriting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session tracking with URL rewriting" Watch "Session tracking with URL rewriting" New topic
Author

Session tracking with URL rewriting

Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
Hi

I am trying to work with session tracking by disabling cookie and using URL rewriting but nothing seems to be work as expected.

please see the code below

Servlet code:



jsp inside the folder jsps:


So when i click the link on the servlet it always shows true in the jsp.

Why the URL rewriting is not working in this case?


SCJP 6,SCWCD 5,SCBCD 5

Failure is not an option.
Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
The corrected version of line 16 is

out.println("<a href=\"" + response.encodeURL("jsps/sessionJsp1.jsp\"") + "\\>click me</a>");
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17


Why are you sending the " inside the encodeURL method?? Try this

Also, when you post some HTML code in the code tags, select the "Disable HTML in this message" checkbox, that way your HTML won't get screwed up...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
Thanks Ankit...

A little double qoute solved the problem.
Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510

I found this from Head First WCD book


URL rewriting adds the session ID to the end of all the URLs in the
HTML that you write to the response.



this is my jsp


this is my servlet


this is sessionJsp.jsp
[code]
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%= session.isNew() %>
Session Attribute : ${sessionScope.sessionAttr}
</body>
</html>
[code]

i can't see anywhere that it adds session ID to the end of url?
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

I found this from Head First WCD book

Wow, a new book of the Head First series is available (just kidding, I think you are talking about Head First Servlets and JSP).
i can't see anywhere that it adds session ID to the end of url?

Did you check the output of the URL servlet in the browser, the link that it generates (which is by the way wrong as there is no wrapping <html> and <body> tag) must have the session ID appended to it...
Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
Make sure you disable cookies in your browser.

In IE8 even after disabling cookies i can not see the session id appended at the URL and upon seeing the request monitor in Netbeans the cookie is sent by the client.I am not sure how IE8 accepts cookies even after i disable it.

But it works perfectly fine with mozilla.

Let me know if you still have problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session tracking with URL rewriting
 
Similar Threads
HTTP Status 404 - Servlet is not available
How to call a JPA-Facade from a JSP
org.apache.jasper.JasperException: java.lang.ArrayIndexOutOfBoundsException: 8
Hello world ejb3 problem
EJB, JNDI