Struts2 URL无法访问 [英] Struts2 URL unreachable

查看:134
本文介绍了Struts2 URL无法访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很喜欢Struts2,可以省略部分路径来访问JSP页面.请注意该路径假定包含pages/welcome_user.jsp.关键是要查看路径中的单词pages.

I'm really racking my head here with Struts2 - I'm able to access the JSP pages by omitting part of the path. Note the path suppose to include pages/welcome_user.jsp. The key is to look at the word pages in the path.

这是struts.xml文件:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

    <package name="default" namespace="/User" extends="struts-default">
        <action name="Login">
            <result>pages/login.jsp</result>
        </action>
        <action name="Welcome" class="com.mkyong.user.action.WelcomeUserAction">
            <result name="SUCCESS">pages/welcome_user.jsp</result>
        </action>
    </package>
</struts>

我可以通过以下方式访问login.jsp:http://localhost/Struts2Example/User/Login
welcome_user.jsp通过:http://localhost/Struts2Example/User/Welcome
请注意,在两个URL中,我都可以删除pages,为什么?

I'm able to access login.jsp via: http://localhost/Struts2Example/User/Login
and welcome_user.jsp via: http://localhost/Struts2Example/User/Welcome
Note that in both URL, I'm able to drop pages, why?

来源: http://www.mkyong.com/misc/how-to- use-mkyong-tutorial/

有人可以通过上面的教程告诉我什么地方出问题了吗?

Can someone go through the above tutorial and tell me what's wrong?

推荐答案

首先,您已使用映射到struts.xml中的操作的URL.

First, you have used URLs that are mapped to the actions in the struts.xml.

执行action方法并返回结果代码SUCCESS.您可以在操作配置中找到此结果.然后,如果未设置结果类型,则执行结果,默认值为dispatcher,并将请求转发到结果配置中指定的位置.

The action method is executed and returns a result code SUCCESS. This result you can find in the action config. Then result is executed, if the type of result isn't set the default is dispatcher, and request is forwarded to the location specified in the result config.

如果位置是相对的,则最终绝对位置将由用于此操作的程序包的名称空间确定.

If location is relative the final absolute location will be determined by the namespace of the package used for this action.

用法名称空间的更详细示例和说明,您可以在示例 Struts 2命名空间配置示例和说明.

More detailed example of usage namespaces and explanation you can find in the example Struts 2 Namespace configuration example and explanation.

如果使用转发到JSP的dispatcher结果,则不能删除页面.在这种情况下,URL已被重写,您看不到最终URL.

You can't drop pages if you are using dispatcher result that forwards to JSP. In this case the URL has been rewritten and you can't see the final URL.

这篇关于Struts2 URL无法访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆