• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Url Rewriting

 
Nabila Mohammad
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wanted how sessions are maintaines through url rewriting and not throught Cookies.
I wrote this program to find out about session in cookies..
But I am not sure how to use the same program for urlrewriting..


My SessionServlet.java



and the form.jsp is


And my web.xml is:



Now I am sure where to fit the url rewriting ..which is mentioned in HFSJ as ...




out.println("click me");
This line gives a hyperlink.
When we click on click me it goes to /sissy.do.


Now if i change my form.html to <form method="get" action="MyUrlRewritingServlet.do">
The parmeters of the form will not be passed.

So i am not sure how to make this work and see the results of UrlRewriting...

Can someone please help with the code...

 
Chinmaya Chowdary
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Nabila.

Use in 'MyUrlRewritingServlet' class and,

Modify web.xml little,
Inorder to see wether url rewriting is working or not, disable cookies in browser.
 
Nabila Mohammad
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Chinmaya...

but still cant get the code to work..

I am getting the error
The requested resource (/sissy2.do) is not available.

I suppose there is some problem with :



As it cant get access to sissy2.do.


Is it something to do with the path ...?



 
Chinmaya Chowdary
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Nabila.

We should use relative path,
If we say, response.encodeURL("/sissy2.do"); it will go to the server root.
 
Chinmaya Chowdary
Ranch Hand
Posts: 434
posted 6 years ago
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Nabila.
But the parameters ie. Name and Age is not passd on to "sissy2" file.I get a null value .
Is there any way i can pass it on to sissy2 from sissy?

Get the form parameters in 'MyUrlRewritingServlet' class and store them in 'session' scope. Get these 'session' attributes in 'MySessionServlet' class.
I cannot understand the significance of using a hyperlink for Url encoding ie.
Isnt there any way to do url encoding with out clicking on "click me" or with out using a hyperlink,

For this use, in 'MyUrlRewritingServlet' class.
I am trying to run this code.. to display the name and value of all cookies that is existing with in a request.
I know there is atleast one ie. JSESSION ID. Since I am using UrlRewriting.
But i keep getting a Null Pointer Exception.

Since we disable cookies in browser to test wether url rewriting is working or not, we don't get cookies at the container. If we use url rewriting container use, name of the session id as 'jsessionid' and follwed by its value. As far I know here 'jsessionid' is not a cookie.
 
Nabila Mohammad
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am not sure how to store parameters in session scope.
If you could you help me with it..i woud really appreciate it!

Thanks for your answers.They were really helpful.
The cookies not being displayed made sense.. since cookies were disabled

But there is one thing....
When i run the same code with cookies enabled and without url rewriting( i didnot use the MyUrlRewritingServlet file at all) , I get the output :

My cookie name is JSESSIONID and value is 79ECABE90D7E5F2CDAF48D3F07061F9B
(The only cookie that exists )

Wouldn't that mean JSESSIONID is a cookie?
 
Chinmaya Chowdary
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Nabila.

I am not sure how to store parameters in session scope.

Get the form parameters and set them in session scope like,

Add it in 'MyUrlRewritingServlet' class.

And get the session scope attributes in 'MySessionServlet' class like

When i run the same code with cookies enabled and without url rewriting( i didnot use the MyUrlRewritingServlet file at all) , I get the output :

My cookie name is JSESSIONID and value is 79ECABE90D7E5F2CDAF48D3F07061F9B
(The only cookie that exists )

Wouldn't that mean JSESSIONID is a cookie?

Yes, it is 'JSESSIONID' cookie. I think 'form.jsp' sets that cookie.
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use:
<%@ page session="false" %>
to prevent session's auto-creating by JSP page ;)
 
Nabila Mohammad
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Chinmaya and lucas..

finally got the output i wanted!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic