This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Servlet URL repeating Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet URL repeating " Watch "Servlet URL repeating " New topic
Author

Servlet URL repeating

Anthony Smith
Ranch Hand

Joined: Sep 10, 2001
Posts: 285
At the end of most of my servlets, I use the following code, and it forwards to that next page but still keeps the same URL. Eventually the URl will get repeated and repeat itself like so with other servlets: http://127.0.0.1/servlet/Logout/servlet/LoginServlet/
How do I stop this?

RequestDispatcher rd =
getServletContext().getRequestDispatcher(next_url);
rd.forward(request, response);
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
That's the way it's supposed to work
When a web component dispatches a request to another server Web component you are telling the server (at the end of the chain) to send to your browser (Oops! I meant Internet Client! Sorry M. Andreessen!) an HTML (or XML) response that your client will understand and your browser stays with the same URL. The same one that initiated the (possible) chain reaction in the server that resulted in said response.
If, on the other hand, the response from the server is a sendRedirect, that instructs your Internet client to go to another URL and so that field changes in your browser in that case.


Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Anthony,

What Tony said... but I notice something about your URL. you've got /servlet/Logout/servlet/LoginServlet

Do you mean that every time you forward to a new servlet, you end up appending a new /servlet/xxxx onto the end of your URL appearing in the browser's address bar? Such that you have /servlet/a/servlet/b/servlet/c/servlet/d, etc, etc... ?

This is definately pretty freaky behaviour.
Edward Farrow
Ranch Hand

Joined: Apr 02, 2002
Posts: 32
a similar question was posted a few weeks back. could be a path issue, check the path in your html form or your next_url and try preceding it with a / (slash) or if you alread have a slash try getting rid of it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet URL repeating
 
Similar Threads
HTTP Status 405 error comes
Servlet Aliasing
Servlet Context Path Issue
Get the URL of the page being redirected to?
problems with servlets on Weblogic 6.1