1. <html:img src="">
src属性指定完整的URI,看两个具体的实例
http://127.0.0.1:8080/MyNetStore2/WebRoot/index.jsp http://127.0.0.1:8080/MyNetStore2/WebRoot/shopping/shoppingHome.jsp
应用的目录结构:
webapps
+
+----MyNetStore2
+
+----WebRoot
+------include(header.jsp, sidebar.jsp, indexContent.jsp, footer.jsp,layout.jsp)
+-----index.jsp
+-----images
+-----shopping
+------shoppingHome.jsp
+-------include(shoppingHead.jsp,productTree.jsp, productList.jsp
layout2.jsp, footer.jsp)
在index.jsp中这样插入images下的图片:
"images/logo.gif" alt="Fish" border="0"/>
shoppingHome.jsp
中这样插入
images下的图片:
"../images/logo_small.gif" alt="logo" border="0"/>
很明显,
index.jsp的目路径为:
http://127.0.0.1:8080/MyNetStore2/WebRoot/,于是要访问i
mages下的资源,只需要这个路径下加上
images/logo.gif,从而构成
http://127.0.0.1:8080/MyNetStore2/WebRoot/
images/logo.gif,这即是指定了该图片的完整的
URI。同理,
shoppingHome.jsp的路径为:
http://127.0.0.1:8080/MyNetStore2/WebRoot/shopping/,要想访问到
mages下的资源就必须返回到
/shopping的上一层路径即WebRoot/,用
../这样的方式返回到
shopping的上一层路径,此时构成了
http://127.0.0.1:8080/MyNetStore2/WebRoot/shopping/
../images/logo_small.gif的路径,也即是
http://127.0.0.1:8080/MyNetStore2/WebRoot
/images/logo_small.gif2.<tiles:insert flush="" page="">
始终要记住page属性指定的是相对于当前页面的URI,</tiles:insert> <html:img page="">中这点同样适用。
下面是index.jsp的部分相关源码
<tiles:insert page="include/layout.jsp" flush="true"> <tiles:put name="header" value="shoppingHead.jsp"/> <tiles:put name="sidebar" value="productTree.jsp"/> <tiles:put name="content" value="productList.jsp"/> <tiles:put name="footer" value="footer.jsp"/> tiles:insert>
下面是
shoppingHome.jsp
的部分相关源码:
<tiles:insert page="include/layout.jsp" flush="true"> <tiles:put name="header" value="shoppingHead.jsp"/> <tiles:put name="sidebar" value="productTree.jsp"/> <tiles:put name="content" value="productList.jsp"/> <tiles:put name="footer" value="footer.jsp"/> tiles:insert>
可以看到这两个jsp文件所用到的包含文件的目录结构完成不同,但是为什么它们的源文件的目录结构一样呢,可以这样看:
layout2.jsp的完整URI为:
http://127.0.0.1:8080/MyNetStore2/WebRoot/shopping/
include/layout2.jsp,由于只需给出相对路径,于是
page="include/layout2.jsp,同理
layout.jsp的完整URI为
http://127.0.0.1:8080/MyNetStore2/WebRoot/index.jsp ,给出相对路径,于是
page="include/layout.jsp"。