在Eclipse中进行Web开发的路径问题

一、在struts.xml文件中配置Action执行后的跳转资源

Action执行后的跳转资源位置是通过<result>标签指定的,在指定资源位置时可以用绝对路径,也可以使用相对路径。

绝对路径是以"/"开头,"/"代表当前Web应用的上下文路径;

相对路径不以"/"开头,相对于当前执行的action的路径,也就是namespace指定的路径。

例如:

<package name="default" extends="struts-default" namespace="/admin">
    <action name="login" class="com.cn.LoginAction">
        <result>success.jsp</result>
        <result name="error">/error.jsp</result>
    </action>
</package>
假设当前Web应用的上下文路径是/bbs,那么执行/bbs/admin/login.action成功后,会跳转到 /bbs/admin/success.jsp;如果执行结果为失败,会跳转到 /bbs/error.jsp

二、jsp文件中的路径(了解)

问题背景:

在Struts2框架中,web.xml文件的配置如下:

<filter>
    <filter-name>Struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>Struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

struts.xml文件配置如下:

<struts>
    <constant name="struts.devMode" value="true"/>
    <package name="path" extends="struts-default" namespace="/path">
        <action name="path" class="com.cn.PathAction">
            <result name="path">/path.jsp</result>
        </action>
    </package>
</struts>

Action中execute方法的返回值为"path"

当Action执行后会跳转至path.jsp页面,当在一个jsp页面(如path.jsp)中指定一个链接(如<a href="index.jsp">index.jsp</a>)时,此时path.jsp和index.jsp在同一目录(Web-INF)下,当在path.jsp页面中点击index.jsp链接时,会报404错误(找不到index.jsp),此时URL地址栏为:http://localhost:8080/webapp/path/index.jsp。这就说明jsp页面中写的相对路径并不是以当前jsp文件所在目录为根目录,而是以action的路径来确定的。


参考来源:http://www.cnblogs.com/LuckyBao/p/6010832.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值