• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 997
  • Last Modified:

Using Paths Relative to Document Root in Tomcat/JSP

I am new to Tomcat/JSP and I have what I think is a fairly simple question, I just don't know enough to figure it out. I have a webapp with the following structure.

myapp
---src
---build
---WebRoot
------css
---------main.css
------images
---------image1.jpg
---------image2.jpg
------index.jsp

From index.jsp, if I want to reference my image1.jpg, it will work if I use src="images/image1.jpg", but src="/images/image1.jpg" doesn't. Same goes for stylesheets. I know that this must have something to do with what Tomcat considers the document root, but I can't figure out how to make it work.

Is there a way to use paths relative to the document root instead of relative to the current file? Maybe there's some configuration setting that I'm missing?
0
lukeinjax
Asked:
lukeinjax
1 Solution
 
rrzCommented:
This question was just recently asked at
http://www.experts-exchange.com:80/Software/Server_Software/Application_Servers/Java/Apache_Tomcat/Q_22700466.html
Use should use
src="<%= request.getContextPath() %>/images/image1.jpg",
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now