1. Description of the problem
Configuration action in the add () method to access the call using wildcards way struts.xml in http: // localhost: 8080 / Struts2Demo / helloworld_add.action time, there was the familiar error:
HTTP Status 404 – Not Found
Type Status Report
Message There is no Action mapped for namespace [/] and action name [helloworld_add] associated with context path [/Struts2Demo].
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/8.5.35
2, the relevant code
struts.xml relevant code portion
<package name="default" namespace="/" extends="struts-default">
<action name="helloworld_*" method="{1}" class="com.icheny.action.HelloWorldAction">
<result>/result.jsp</result>
<result name="add">/{1}.jsp</result>
<result name="update">/{1}.jsp</result>
</action>
</package>
HelloWorldAction.java relevant code portion
public String add()
{
return "add";
}
public String update()
{
return "update";
}
3 reasons
Since struts2 2.5 version of safety to the next level, prohibit the use of wildcards, all unsecured access must be allowed to be declared in struts.xml. I use the 2.5.16 version of the struts, and therefore the emergence of this mistake.
4. Solution
Add attributes in the package: strict-method-invocation = "false"
struts.xml package part of the code after modification of:
<package name="default" namespace="/" extends="struts-default" strict-method-invocation="false"> <action name="helloworld_*" method="{1}" class="com.icheny.action.HelloWorldAction"> <result>/result.jsp</result> <result name="add">/{1}.jsp</result> <result name="update">/{1}.jsp</result> </action> </package>
Another visit HTTP: // localhost: 8080 / Struts2Demo / helloworld_add.action , normal jump: