File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes encodeURL problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "encodeURL problem" Watch "encodeURL problem" New topic

encodeURL problem

sasikumar palakkizhi

Joined: Sep 11, 2005
Posts: 29
I was trying to experiment with the use of encodeURL( String). I did the experiment with getSession() and encodeURL(). The code is shown and the problem is mentioned below the code.

It is found that if I use getSession() (As shown above. encodeURL is commented) , the execution goes to "else" part whenever I refresh the page. When I comment getSession() and include the encodeURL("." ) line, execution never goes to the else part..Could anybody point out the mistake.. I am using Tomcat 5.5 as my server.

thanks in advance

Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

This problem is not related to encodeUrl, but with the way you are using getSession. Calling getSession() will return an existing session, or create a new one if it doesn't already exist. If you comment this out, no session will be created, so you'll always end up in the if{}. If you leave it, you'll end up in the else{} after the session has been created.

[My Blog]
All roads lead to JavaRanch
sasikumar palakkizhi

Joined: Sep 11, 2005
Posts: 29
Hi Satou kurinosuke,

Thanks for the reply, I tried again.

I realised that encodeURL and getSession() works together to get the session information if the Cookies are disabled...


Ben Souther

Joined: Dec 11, 2004
Posts: 13410

I can't see where you are declaring your the variable "session".
I'm assuming that it's in the service (doPost or doGet) method.

With every hit, you're testing the 'session' variable for nullness and then setting it's value it it's null. With this logic, it will always be null.

Call request.getSession before testing for nullness.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: encodeURL problem
It's not a secret anymore!