File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes JSP relative link/path problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP relative link/path problem" Watch "JSP relative link/path problem" New topic

JSP relative link/path problem

Girish Wakure

Joined: Apr 14, 2010
Posts: 28
I have a problem in relative path.
we have developed a Web Application using Struts2, editor - Eclipse and web server - jetty-6.1.3.
Project works fine in eclipse with jetty .
now I am deploying it to the Tomcat 7 web server.

Problem comes when I access the relative links.
for example -
when I run in eclipse - jetty, I get application url as http://localhost:8080/base/mainMenu.html and so on..

when run from Tomcat deployment I get url as http://localhost:8080/myApplication/base/mainMenu.html as deployed as war file.
when I click on any link (eg /base/action_name) instead of going to http://localhost:8080/myApplication/base/action_name
it gives http://localhost:8080/base/action_name which results in page not found error.

if I try to remove / from relative path (eg base/action_name) it gives http://localhost:8080/myApplication/base/base/action_name

Please help me out..
Girish Wakure

Joined: Apr 14, 2010
Posts: 28
I need a solution which works on both.
Because I am continuing development in same environment (Eclipse - jetty) but need to deploy application in tomcat.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63858

You need to include the context path in resource URLs. See the JSP FAQ for more information, but the EL expression ${pageContext.request.contextPath} will resolve to the context path for the application.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: JSP relative link/path problem
It's not a secret anymore!