• Post Reply Bookmark Topic Watch Topic
  • New Topic

Easy question for gurus  RSS feed

 
MrIT
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a servlet that I call and pass parameters via an "a herf="servlet/myServlet?action=getAll".
In the servlet the dispatcher forwards the request to the correct jsp page. Everything works fine execep that when the servlet is finished the url (address in the browser) reads "servlet/myServlet/action=getAll". How can I get it to read the jsp page that the servlet passed it to in the url.
Thanks for you help.
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MrIT
Welcome to the Java Ranch, we hope you�ll enjoy visiting as a regular however,
your name is not in keeping with our naming policy here at the ranch. Please change your display name to an appropriate name as shown in the policy.
Thanks again and we hope to see you around the ranch!!
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it depends on what kind of mechanism your dispatching servlet is using to forward the request.... are you using a response.sendRedirect() or a RequestDispatcher.forward() ?
-- response.sendRedirect() will actually instruct the browser to make a new request to the specified URL (thus the address displayed in the browser will reflect the page visited)
-- requestDispatcher.forward() passes control of the request to another resource -- it is completely transparrent to the user, and the address in the browser will remain the same as the orginal URL.
 
MrIT
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wow that was fast, thanks.
oh ok. I am using RequestDispatcher.forward(). So I should use the response.sendRedirect() in the serverlet or jsp page. If I put it in the servlet, does it go right after the RequestDispatcher.forward()? I stil need to pass a vector to the jsp page.
Thanks for you help !
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've not played with either method much -- check the API and the spec and figure out which behavior you want to use -- play with it a bit -- you'll figure it out!
Also, I'm sure if you search this forum and the Servlet Forum -- I'm sure you'll find plenty of discussion.
Lastly -- Make sure you adjust your displayed name to match the JavaRanch Naming Policy.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!