File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes context path in the of struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "context path in the of struts" Watch "context path in the of struts" New topic

context path in the of struts

az ziz
Ranch Hand

Joined: Dec 17, 2008
Posts: 50
i use images in the jsp using the html:image tag with the srcKey="imageurl", the value of the key contains the image resource location. how to include the context path in the resource than using like this, ../../images/image1.gif?
az ziz
Ranch Hand

Joined: Dec 17, 2008
Posts: 50
please note this,
`<img src=<bean:message arg0="<%=request.getContextPath()%>" key="image1"/>>` works. but i cant change in 100s of jsp files which uses html:image.

Prakash Mani - Attur
Ranch Hand

Joined: Oct 08, 2009
Posts: 100
hi az ziz

create a folder named images under web content and add all the images to the images folder.
now you can use like this

az ziz
Ranch Hand

Joined: Dec 17, 2008
Posts: 50
yes, all the images are in images folder only. but the problem is with the relative path the old developers has given, ../../images now the context path is changing, so as the request uri changes the images in the jsp and their paths changes

my_project/transaction/a.jsp was the request
../images/img1.jpg will work
if the same was changed to my_project/a.jsp
../images/img1.jpg wont work

said above,
../images/img1.jpg will work were mapped in the message properties file of struts.
how to append the context path with the path than ../../

David Newton

Joined: Sep 29, 2008
Posts: 12617

Use an absolute path.
I agree. Here's the link:
subject: context path in the of struts
Similar Threads
Problem with servlet running on linux.
easy uri context path req.getRequestURI()
Point to an image in a javascript
include file in jsp
Adding images to Jar Files (NetBeans)