File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes URL rewriting is not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "URL rewriting is not working" Watch "URL rewriting is not working" New topic
Author

URL rewriting is not working

priya rishi
Ranch Hand

Joined: Oct 26, 2008
Posts: 119
I have problem in url rewriting , when i disabled cookies and trying to use response.encodeURL() method, my session is lost and
session.isNew() always returns true.
please any help.

my programs are:
program 1 - select.java



program 2 - result.java




SCJP 5 , SCWCD 5
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42928
    
  68
The first step in debugging this is to check whether the URL actually contains the session information. If it doesn't, then of course the session would always be new, because no session ID would be transmitted.

Looking at the first code snippet, it seems that you encode the URL before the session is being created. While I'm not sure how URL encoding works in detail, I'd guess that encoding the URL before creating the session can't work because the container has no session (and thus no session ID) associated with the request at that point.
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi Priya. As Ulf Dittmer said
Looking at the first code snippet, it seems that you encode the URL before the session is being created.
is true.

Use in 'select.java'.
priya rishi
Ranch Hand

Joined: Oct 26, 2008
Posts: 119
Thanks for your replies.

The first step in debugging this is to check whether the URL actually contains the session information.


My code is now -


url prints result , not encoded result.but why?
The container should try both cookies and URL rewriting , for the first response it sends.
any suggestions?

Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi Priya.
url prints result , not encoded result.but why?
The container should try both cookies and URL rewriting , for the first response it sends.
any suggestions?

Inorder to see the affect, first we need to delete all the cookies in the browser. The container try both cookies and URL rewriting, for the first response it sends. The interest thing here is that, when first request sent to the container, the container creates session object and constructs cookie object by using its session id, name, like I think, in between some where it checks will the browser accepts the cookies or not? If found no, then url rewriting will happen and sends session id's through both url rewriting and cookies.
priya rishi
Ranch Hand

Joined: Oct 26, 2008
Posts: 119
Hello,

Chinmaya wrote:
The container try both cookies and URL rewriting, for the first response it sends. The interest thing here is that, when first request sent to the container, the container creates session object and constructs cookie object by using its session id, name, like


I understand the concept theor..

My question is :


i am not able to retrieve encoded url .

output is - url is result.

this is what i want - url is result;jsessionid=some id

thanks.
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


this is what i want - url is result;jsessionid=some id


Did you block / disable the cookies in browser ? If Container finds somehow that the client browser support cookies , encodeURL will return only URL and not encoded with jsession id.
priya rishi
Ranch Hand

Joined: Oct 26, 2008
Posts: 119
Did you block / disable the cookies in browser ?


yes , i blocked the cookies.
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi Priya. After blocking the cookies, is url rewriting working?
priya rishi
Ranch Hand

Joined: Oct 26, 2008
Posts: 119
hello,
Hi Priya. After blocking the cookies, is url rewriting working?



No , its not.
since the start, i have been trying this program with cookies blocked only.
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
I tested this in Tomcat5.5.9 and url rewriting is working fine. Can you please tell, which server/container you are using?
Maciej Drozdzowski
Ranch Hand

Joined: Dec 30, 2009
Posts: 40

same problem here, i'm using 6.0.20.
cookies blocked, cookies cleared. not working on ff and ie.
any ideas?
Maciej Drozdzowski
Ranch Hand

Joined: Dec 30, 2009
Posts: 40

ok, problem solved.
kinda funny though, i don't remember reading about the reasons in any book or spec or seeing them while googling. my memory might be not working well though

the main reason is - the url encoded cannot point to another application!

for example, my current link is

i can do that:

and that

but i cannot do that:


i came up wth the solution after debugging through some of tomcat's code. any specific reason for that?
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi, Maciej.

If 'userA'(who disables cookies at the browser side) participates in session with application 'WebApp1', wants to access resource from application 'WebApp1'. And in that resource suppose if there is response.encodeURL, Here container appends the 'jsessionid:' at the end of resource 'target.do' and the response will be sent to the client. Every time 'userA' communicates with this unique session id with the application 'WebApp1'. Now the application checks is there is any session object present associated with this id. Here it is 'yes'. It will communicates with this user.
Incase of

Suppose if the container appends the 'jsessionid:' to the resource '/API/target.do1' and sends the response to the client. Now if the client(userA) clicks this url then 'jsessionid:' will follows with url. Now the request goes to the another application 'WebApp2'. Now the application 'WebApp2' gets the session id from the url and checks is there any session object associated with this id? Here it is false. Since this is different application and session id's will be created uniquely. Nothing to do with this session id.


Because of this 'encodeURL("/WebApp2/target.do")' method checks the resource(/WebApp2/target.do) wether it is going out of this application(WebApp1) scope by checking the slash '/' before the resource? If it is true, then the 'jsessionid:' will not be appended to the resource. If no appends.

Please check once for the resource wether 'jsessionid:' appends or not? I tested this in Tomcat5.5.9 and it will not append.
Maciej Drozdzowski
Ranch Hand

Joined: Dec 30, 2009
Posts: 40

Chinmaya, thanks for your interest.

I absolutely understand your explanations and totally agree. At the time of writing my code, it simply didn't occur to me that these are two different webapps. I just have one bigger application from which i'm redirected to my smaller apps which i use for studying and it all was one big app for me it was perhaps too late ;)

Chinmaya Chowdary wrote:Please check once for the resource
wether 'jsessionid:' appends or not? I tested this in Tomcat5.5.9 and it will not append.

works perfectly.

here's a part of tomcat's code


must be a new thing then.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: URL rewriting is not working