Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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

Request Dispatcher problem

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

Basically my problem is to do with the request dispatcher displaying
http://localhost:8080/musicStore/CartServlet.do in the address bar of pages it's forwarded to, instead of http://localhost:8080/musicStore/cart/index.jsp if you had clicked on a normal hyperlink (thereby altering links relative to the page).

A page listing some quick links to choose records is my index.jsp file and is located in c:\tomcat\webapps\musicStore\cart\index.jsp

If you open this page by typing in http://localhost:8080/cart/index.jsp
then it opens with the above address written in firefox's address bar.
If you then click on one of the links
<a href="../CartServlet.do?productCode=8601">Add To Cart</a>
then it correctly maps in the servlet mapping and runs the servlet CartServlet.
I have included the mappings from web.xml:



This all works fine ONLY IF you arrive at the page index.jsp by way of a normal hyperlink like "/musicStore/cart/index.jsp".

I seem to be having problems with my request dispatching. From the cart servlet I have the code

url = "/cart/index.jsp";
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher(url);
dispatcher.forward(request, response);

When the cart servlet runs and dispatches me to the page index.jsp then in my brower's address bar http://localhost:8080/musicStore/CartServlet.do is written. This may be the reason why when I click on one of the links on the index.jsp page then I get the error HTTP Status 404 - /CartServlet.do.
If I amend the huperlinks to
<a href="CartServlet.do?productCode=8601">Add To Cart</a> thereby taking off the ../ prefix then it will work when forwarded by the request dispatcher but not when hyperlinked through from another page.

My question is why do pages the request dispatcher fowards to display
http://localhost:8080/musicStore/CartServlet.do in the address bar, and thereby alter relative links?? Is there a way to fix this please?

Thanks
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic