Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet URL repeating

 
Anthony Smith
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic