Struts 2.5.2 HTTP Status 404 - There is no Action mapped for namespace [/] and action name [regist_A
2016-08-04 14:57
1811 查看
使用Struts2.5.2 学习Action通配符时,出现错误:HTTP Status 404 - There is no Action mapped for namespace [/] and action name [regist_Action] associated with context path [/wildcard1].
在确保代码无误的情况下,用Struts2.3 JAR包代替后可正常使用,而Struts2.5不行,最后确定是Struts2.5.2 JAR本身的问题。
查看文档struts-2.5.2\docs\docs\action-configuration.html后找到问题所在。
首先,2.3版本中多了一个Strict DMI,当设置包属性
而2.5版本中的 Method Invocation(SMI)继承了2.3中的Strict DMI,属性strict-method-invocation被默认设置为true,所以才会出现这个错误。
解决方法:修改struts.xml,在<allowed-methods>准确添加method
<struts>
<package name="lee" extends="struts-default">
<action name="*_Action" class="org.crazyit.app.action.LoginRegistAction"
method="{1}">
<!-- 定义逻辑视图和物理视图之间的映射关系 -->
<result name="error">/WEB-INF/content/error.jsp</result>
<result>/WEB-INF/content/welcome.jsp</result>
<allowed-methods>login,regist</allowed-methods>
</action>
<action name="*">
<result>/WEB-INF/content/{1}.jsp</result>
</action>
</package>
</struts>
附docs部分原文:
In Struts 2.3, an option was added to restrict the methods that DMI can invoke. First, set the attribute
via either the
for your action, you do not need to list it in
Note that you can specify
Example struts.xml
In Struts 2.5 the Strict DMI was extended and it's called Strict Method Invocation aka SMI. You can imagine that the DMI is a "border police", where SMI is a "tax police" and keeps eye on internals. With this version, SMI is enabled by default
(
of new configuration option please use the latest DTD definition:
Struts 2.5 DTD
SMI works in the following way:
SMI is enabled but no
SMI is disabled - call to any action method is allowed that matches the default RegEx -
You can redefine the default RegEx by using a constant as follow
When using wildcard mapping in actions' definitions SMI works in two ways:
SMI is disabled - any wildcard will be substituted with the default RegEx, ie.:
SMI is enabled - no wildcard substitution will happen, you must strictly define which methods can be accessed by annotations or
You can configure SMI per
examples below:
SMI via struts.xml
SMI via annotation on action class level
SMI via annotation on package level (in package-info.java)
Allowed methods can be defined as:
literals ie. in xml:
[/code]
patterns when using with wildcard mapping, i.e
RegExs using
Please be aware when using your own
logic in your code as by default only
在确保代码无误的情况下,用Struts2.3 JAR包代替后可正常使用,而Struts2.5不行,最后确定是Struts2.5.2 JAR本身的问题。
查看文档struts-2.5.2\docs\docs\action-configuration.html后找到问题所在。
首先,2.3版本中多了一个Strict DMI,当设置包属性
strict-method-invocation="true"时,Struts会拒绝一切不明确的方法属性包括通配符。(有点难翻译,具体看原文)
而2.5版本中的 Method Invocation(SMI)继承了2.3中的Strict DMI,属性strict-method-invocation被默认设置为true,所以才会出现这个错误。
解决方法:修改struts.xml,在<allowed-methods>准确添加method
<struts>
<package name="lee" extends="struts-default">
<action name="*_Action" class="org.crazyit.app.action.LoginRegistAction"
method="{1}">
<!-- 定义逻辑视图和物理视图之间的映射关系 -->
<result name="error">/WEB-INF/content/error.jsp</result>
<result>/WEB-INF/content/welcome.jsp</result>
<allowed-methods>login,regist</allowed-methods>
</action>
<action name="*">
<result>/WEB-INF/content/{1}.jsp</result>
</action>
</package>
</struts>
附docs部分原文:
Strict DMI
In Struts 2.3, an option was added to restrict the methods that DMI can invoke. First, set the attribute strict-method-invocation="true"on your
<package>element. This tells Struts to reject any method that is not explicitly allowed
via either the
methodattribute (including wildcards) or the
<allowed-methods>tag. Then specify
<allowed-methods>as a comma-separated list of method names in your
<action>. (If you specify a
methodattribute
for your action, you do not need to list it in
<allowed-methods>.)
Note that you can specify
<allowed-methods>even without
strict-method-invocation. This restricts access only for the specific actions that have
<allowed-methods>.
Example struts.xml
Strict Method Invocation
In Struts 2.5 the Strict DMI was extended and it's called Strict Method Invocation aka SMI. You can imagine that the DMI is a "border police", where SMI is a "tax police" and keeps eye on internals. With this version, SMI is enabled by default(
strict-method-invocationattribute is set to
trueby default in
struts-defaultpackage), you have option to disable it per package - there is no global switch to disable SMI for the whole application. To gain advantage
of new configuration option please use the latest DTD definition:
Struts 2.5 DTD
<allowed-methods>/
@AllowedMethodsis defined per action - SMI works without switching it on but just for those actions (plus adding
<global-allowed-methods/>)
SMI is enabled but no
<allowed-methods>/
@AllowedMethodsare defined - SMI works but only with
<global-allowed-methods/>
SMI is disabled - call to any action method is allowed that matches the default RegEx -
([A-Za-z0-9_$]*)
You can redefine the default RegEx by using a constant as follow
<constant name="struts.strictMethodInvocation.methodRegex" value="([a-zA-Z]*)"/>
When using wildcard mapping in actions' definitions SMI works in two ways:
SMI is disabled - any wildcard will be substituted with the default RegEx, ie.:
<action name="Person*" method="perform*">will be translated into
allowedMethod = "regex:perform([A-Za-z0-9_$]*)".
SMI is enabled - no wildcard substitution will happen, you must strictly define which methods can be accessed by annotations or
<allowed-method/>tag.
You can configure SMI per
<action/>using
<allowed-methods/>tag or via
@AllowedMethodannotation plus using per
<package/>
<global-allowed-methods/>, see the
examples below:
SMI via struts.xml
literals ie. in xml:
execute,cancelor in annotation:
{""}execute", "[code]cancel
[/code]
patterns when using with wildcard mapping, i.e
<action ... method="do{2}"/>
RegExs using
regex:prefix, ie:
<global-allowed-methods>execute,input,cancel,regex:user([A-Z]*)</global-allowed-methods>
Please be aware when using your own
Configurationproviderthat the logic to set allowed methods is defined in built-in providers -
XmlConfigurationProviderand
PackageBasedActionConfigBuilder- and you must replicate such
logic in your code as by default only
executemethod is allowed, even when SMI is disabled.
相关文章推荐
- struts.xml不在默认位置,导致出现HTTP Status 404 - There is no Action mapped for namespace [/] and action name [
- HTTP Status 404 - There is no Action mapped for namespace [/] and action name [login!welcome] associ
- HTTP Status 404 - There is no Action mapped for namespace [/] and action name [] associated with con
- 解决HTTP Status 404 - There is no Action mapped for namespace [/] and action name [] associated with c
- HTTP Status 404 - There is no Action mapped for namespace [/] and action name [hello] associated wit
- HTTP Status 404 - There is no Action mapped for namespace [/] and action name [BsMmWeb] associated w
- HTTP Status 404 - There is no Action mapped for namespace [/] and action name [userAction!add] assoc
- Struts2:HTTP Status 404 - There is no Action mapped for namespace[ / ]and action name singleUpload.
- ssh整合DWR的时候报 HTTP Status 404 - There is no Action mapped for namespace / and action name bookInfo.
- HTTP Status 404 There is no Action mapped for namespace / and action name
- HTTP Status 404 - There is no Action mapped for namespace / and action name schemeList.
- 异常HTTP Status 404 There is no Action mapped for namespace / and action name
- Struts2框架中HTTP Status 404 There is no Action mapped for namespace / and action name
- HTTP Status 404 There is no Action mapped for namespace / and action name
- HTTP Status 404 - There is no Action mapped for namespace /jsp and action
- HTTP Status 404 - There is no Action mapped for namespace /jsp and action name login. type Status re
- 一个struts傻瓜式的问题There is no Action mapped for namespace [/] and action name [] associated with context
- maven jetty struts异常 There is no Action mapped for namespace [/] and action name [] associated with context path
- HTTP Status 404 - There is no Action mapped for namespace [/] and action name [result] associated wi
- struts 配置出现错误 There is no Action mapped for namespace [/] and action name [findPage] associated with