URI资源路径


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.gif

2.<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"。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值