一个简单又复杂的问题,struts下如何合理的使用图片的URL地址,各路高手都来看一下。
现在我需要达到配置web的发布路径同时更改该项目所有的页面地址。
例如一个项目,我在tomcat里发布路径为:/prj1
通常对于非Web Content下路径,例如Web Content/user/userLogin.jsp里调用Web Content/user/images/titleBar.jpg,会在userLogin.jsp这么使用titleBar.jpg:
/prj1/user/images/titleBar.jpg
但是有一个问题,prj1这不是写死到页面里了吗?如果以后更改发布路径,那岂不是全部的图片都需要更改?
我又尝试在userLogin.jsp里写成images/titleBar.jpg的相对路径来调用titleBar.jpg,这样登陆的页面没问题,但是一提交问题又来了。ActionForm不通过则经返回到原来的页面,页面地址变成了"http://localhost:8080/prj1/UserLogin.do",返回的页面,titleBar.jpg却显示不了了。因为页面目录改变到了http://localhost:8080/prj1,我的http://localhost:8080/prj1/images/titleBar.jpg却没有图片,图片在http://localhost:8080/prj1/user/images/titleBar.jpg的位置
我的struts-config.xml里这样配置:
<action path="/UserLogin"
name="UserLoginValidateForm"
type="user.UserLogin"
scope="session">
<forward name="success" path="/user/welcomeUser.jsp"/>
</action>
有没有更好点的办法?