• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

question on encodeURL()

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My view.jsp:

My servlet that invokes this view.jsp:

my TestJSP.jsp:


The sequence of invocation of these files are:
servlet invokes view.jsp, then view.jsp shows a link that invokes TestJSP.jsp.

My question:

Since I've blocked the cookies from my browser, I see TestJSP.jsp is invoked with jsessionid in the URL. but how come the view.jsp does not show jsessionid in URL???

Thanks!
Jenny
 
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

My belief is that because your servlet code does not create a session, ie. req.getSession() no session is created in the servlet. Thus the url for the jsp does not have a session id included.

By default jsp's have a session enabled, unless you tell them otherwise, there is a way to do that. So if you have not turned the session off in the jsp the jsp will create one for you by default. Thus the url for test.jsp includes the session id.

if you change your code as per below then the variable test will be false and the url for the view.jsp file will include a session id as a session has now been created.



HTH

Mat
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mat,

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, java.io.IOException { HttpSession session = req.getSession(); String url1 = res.encodeRedirectURL("http://localhost:8080/ELTest/view.jsp"); //Line 14boolean test = "http://localhost:8080/ELTest/view.jsp". equals(url1); //Line 15 System.out.println(test);System.out.println(url1); res.sendRedirect(url1); }


executing with this code, jsessionid is shown in url. But it is not showing when user clicks on Test Link & goes to TestJSP.jsp page.

What is the problem ?
 
Mat Williams
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am not sure why your code is not working. Can you post what you have, as Jenny did, and I (or another member ) will have a look at it and hopefully someone can point you in the right direction.

Mat
 
Jingh Yi
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mat,

I did you said, adding 'HttpSession session = req.getSession();' in servlet code before it redirects to view.jsp. However, I got exactly what Privt got, view.jsp appears with the jsessionid, but testJSP.jsp doesn't have jsessionid. Why?

Thanks! You've been very helpful!
Jenny
 
Mat Williams
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

Sorry for the late reply.

Here is the code I have used and it works for me on tomcat 5.0.28 on Windows XP and 2K

web.xml


TestServletOne.java


TestServletTwo.java


when I use the url http://localhost:8080/RanchTest/TestServletOne ->
I get redirected to view.jsp with NO jsessionid identified in the url bar

when I use the url http://localhost:8080/RanchTest/TestServletTwo ->
I get redirected to view.jsp with a jsessionid identified in the url bar

NOTE that to do this, and this may be the key thing for both of you, I had to turn off cookies -> I seem to remember that someone had something special they had to do in IE there was a post last week sometime about it. Once cookies are turned off the only way the server has to maintain a session id is put it in the url and therefore you see it.

HTH, sorry it is such a long post.

Matthew
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic