• Post Reply Bookmark Topic Watch Topic
  • New Topic

Working with JSP & Servlet paths

 
Matteo Di Furia
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone, I'm developing a web application under Tomcat 5 and I'm facing a problem with paths to JSPs and servlets (I fear it's kinda stupid, but I cannot get out of it).
Basically the web app is working without problems, I got it deployed under my Tomcat and I surf it pointing the browser at http://localhost:8080/<WebAppContext>/index.jsp and so on. When it comes to deploying the webapp in production mode, I can surf it at the address http://www.myweburl.com/index.jsp and so on. I would like to point out that the production server is hosted by a web farm, so I do not have total control over any aspect of the deployment environment. Please notice also that while running locally I have to specify the webapp context, while when running in production mode I have not.
I've read the JSP faq about URLs here on JavaRanch, and I'd say it seems quite clear, but instead I feel like I'm missing something.
In JSP and servlet code I'm managing URLs and forwards like this :

in JSP :



in Servlets :



suppose JSPName.jsp is located in the root directory.

The problem is that while in production mode when I run the servlet it seems to work right, when I run the same servlet locally I get a 404 because the servlet tries to forward me at the page :



i.e. appending twice the context path.
I fear I can't adjust the code to let it run locally, since it will not work in production mode. Again, I feel I'm missing something, how should I code links and forwards to let it run both locally and remotelly, i.e. with and without an explicit context path ? What am I missing ?

Thanks all for kind reply and sorry for such a huge post for such a stupid problem.
[ July 02, 2008: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When request dispatching, you not include the context path. Dispatching is local to the current context, so it doesn't get specified.
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Matteo Di Furia welcome to Javaranch,
as said by Bear, the path is always relative to the current context.
And it does not make any difference whether its development or production.

Thanks all for kind reply and sorry for such a huge post for such a stupid problem.

And no question is stupid, every question has a value and an answer of course .



Hope this helps .
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!