Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Servlet URL repeating

 
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);
 
Desperado
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.
 
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.
 
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.
 
Check your pockets for water buffalo. You might need to use this tiny ad until locate a water buffalo:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic