问题描述
我真的在用 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-使用-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.您可以在操作配置中找到此结果.然后执行result,如果没有设置result类型默认为dispatcher,请求被转发到result配置中指定的位置.
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 Namespace 配置示例及说明.
More detailed example of usage namespaces and explanation you can find in the example Struts 2 Namespace configuration example and explanation.
如果您使用 dispatcher 结果转发到 JSP,则不能删除页面.在这种情况下,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 无法访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)