• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Session tracking with URL rewriting

 
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Siva Masilamani
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The corrected version of line 16 is

out.println("<a href=\"" + response.encodeURL("jsps/sessionJsp1.jsp\"") + "\\>click me</a>");
 
Sheriff
Posts: 9693
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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...
 
Siva Masilamani
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ankit...

A little double qoute solved the problem.
 
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 9693
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic