Struts and Tiles pathing issues.

S

spivee

I am fairly new to struts programming and am trying to learn how to
integrate tiles.

I'm having an odd issue. At least, it's got me stumped... My
defaultlayout.jsp file is in my <webroot>/WEB-INF/pages/layouts folder.
All my images are in <webroot>/images. I have defined my page
definitions in my tiles-defs.xml file. Whem my jsp tiles call an
image, the path to the images is being coded in the browser as
<webroot>/WEB-INF/pages/layouts/images/image.jpg
instead of
<webroot>/images/image.jpg.

Here are some of my config files...

The forward from my struts-config.xml...
<action forward="viewsite.page.default" path="/viewsite" />

The definitions from my tiles-defs.xml file..

<definition name="page.default"
path="/WEB-INF/pages/layouts/defaultlayout.jsp">
<put name="header" value="/WEB-INF/pages/tiles/header.jsp" />
<put name="left_menu"
value="/WEB-INF/pages/tiles/main_left_menu.jsp" />
<put name="body" value="/WEB-INF/pages/tiles/main_body.jsp" />
<put name="right_menu" value="/WEB-INF/pages/tiles/right_menu.jsp"
/>
<put name="footer" value="/WEB-INF/pages/tiles/footer.jsp" />
</definition>
<definition name="viewsite.page.default" extends="page.default">
<put name="left_menu" value="/WEB-INF/pages/forms/viewSite.jsp"
/>
<put name="body" value="/WEB-INF/pages/blank.jsp" />
</definition>

A sample image reference from header.jsp
<img src="images/icon_sm.gif">

I'd appreciate any help.
 
A

Aleksander =?iso-8859-2?Q?Str=B1czek?=

I'm having an odd issue. At least, it's got me stumped... My
defaultlayout.jsp file is in my <webroot>/WEB-INF/pages/layouts folder.
All my images are in <webroot>/images. I have defined my page
definitions in my tiles-defs.xml file. Whem my jsp tiles call an
image, the path to the images is being coded in the browser as
<webroot>/WEB-INF/pages/layouts/images/image.jpg
instead of
<webroot>/images/image.jpg.
[cut]

Read about BASE html element:
http://www.w3.org/TR/html401/struct/links.html#edef-BASE
Struts tag for this element:
http://struts.apache.org/userGuide/struts-html.html#base

Or
render images with html:tag from Struts-html taglib,
and precede url to image with '/':
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html:img page="/images/image.jpg" />

Or
alternatively (but I not recommend this):
<img src="<%=request.getContextPath()%>/images/image.jpg" />
 
S

spivee

Ah, thanks. Actually, the problem was that the struts configuration
tool I'm using (MyEclipse) put in an <html:base /> tag that I hadn't
noticed. Hadn't thought of looking for that.

Thanks for pointing out the base tag. Don't know how long it would
have taken me to find that....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top