对于图片,样式表,js文件等资源的路径用相对路径表示时,以http://localhost:8080/tag/tree/treeAjax.jsp 访问时可以正常访问的,但是经Struts跳转:
http://localhost:8080/tag/renderTreeAction.do 后,这些资源的定位都出现了问题,其原因是这两个url到达同一个jsp后,其相对路径的参照物不同,解决方法是<html:base/>标签,使用此标签后,所有相对路径都已改jsp的路径为参照物.
The base href tag is one of several tags in html that aid in reducing the amount of repetitive text in your document. By declaring a base href you are in affect telling the browser that all relative links contained within the document start from that specified base location. This is a great time saver when developing html on your computer by allowing you to view how the document will look and behave when placed on the server without actually having to do so
<html>
<head>
<title>CodeAve.com(Base Reference)</title>
<base href="http://www.codeave.com">
</head>
<!-- The base href command will set a location from which all
relative links will be driven from. -->
<body bgcolor="#FFFFFF">
Hyperlinks
<p>
<a href=html>CodeAve.com - HTML</a>
即:href=base.href/html
createddue to the base href. Place the mouse cursor over the linkand the full address will appear in the lower left of the browser
Without the base href this link would be directed to the relative location of the page--此页面的相对位置#html
(In this case http://www.codeave.com/html/html
which does not exist) -->
<p>
Image
<p>
<img src=codeavelogo.gif>
<!-- The full url http://www.codeave.com/codeavelogo.gif
will be created due to the base href.
Without the base href this image tag would
be directed to the relative location of the page
(In this case http://www.codeave.com/html/codeavelogo.gif
which does not exist) -->
</body>
</html>