When you configure STRUTS2, there is no error that the action corresponds to the action that the form form fills in.

Source: Internet
Author: User

The previous two days when I built the SSH process, when I wrote a form on the page to submit the form, the system reported the following error:

The There is no action mapped the for Namespace/and action name Saveuser. -[Unknown Location]

At that time, I always thought it was because of my page action write a problem, will report this error, carefully check the page:

<span style= "color: #ff0000;" ><form name= "FM" action= "Saveuser" method= "POST" ></span> <table> <tr> <td&
    				Gt
    			User name: </td> <td> <input name= "User.username" type= "text"/> </td>
    			<td> Nickname: </td> <td> <input name= "User.nickname" type= "text"/>
    				</td> </tr> <tr> <td> Password: </td> <td> <input name= "User.password" type= "password"/> </td> <td> mailbox: </td&
    			Gt
    			<td> <input name= "User.email" type= "text"/> </td> </tr> <tr> <td> Sex: </td> <td> <input name= "User.sex" type= "Radio" value= "1"
   > Male <input name= "User.sex" type= "Radio" value= "0"/> Women </td> 		</tr> <tr> <td> Birthday: </td> <td> <input name=
    				"User.birth" type= "text"/> </td> </tr> <tr> <td colspan= "2" >
    			<input type= "Submit" value= "save"/> <input type= "button" value= "Cancel" onclick= "javascript:void (0);"/> </td> </tr> </table> </form>

Struts.xml file:

<package name= "User" namespace= "/" extends= "Struts-default" >
		<action name= "Saveuser" class= "UserAction" "Method=" Save ">
			<result name=" Save_user ">/webJsp/success.jsp</result>
		</action>
</package>
Web.xml file:

<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>

Found that there is no problem, and then think, because I this SSH is referenced by the company project at that time, I put the struts.xml file in the SRC directory under a struts under the child package, and then think of this piece may be a bit of a problem (also under the reminder of the classmate), I put the struts.xml file alone in the SRC directory, the problem solved:


But, I think, is there a way to access, source below, the struts package in the Struts.xml file? Because if it is to do the project, generally everyone's struts configuration file is one person. So, then search the next struts.xml path, the result is certainly accessible, we only need to configure the following information in Web.xml (Red section):

<filter>
    <filter-name>struts2</filter-name>
    <filter-class> org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilter</filter-class>
    <span style= " Color: #ff0000; ><init-param> 
     <param-name>config</param-name> 
     <param-value> Struts-default.xml,struts-plugin.xml,/source/struts/struts.xml</param-value> 
    </init-param>< /SPAN> 
  </filter>

Because my struts configuration file is in the Struts child package under the source package, and when the project is deployed, STRUS2 defaults to the Struts.xml file under Web-inf classes, which is why the "no Action" is initially reported Mapped "wrong, at that time I thought it was the name of what's written there is a problem, in fact, the root cause is because struts2 is not loaded into the Struts.xml configuration file, so will report this error." And I put the struts configuration file under the source, after the deployment, struts.xml position in the Web-inf/classes/source/struts directory, so the <param-value> corresponding to it.

Also note that if the <param-name>config</param-name> parameters are configured, Then struts-defual.xml such as loading files may be placed in, otherwise it will not automatically load and error, there are struts-plugin.xml files, perhaps to put here, because struts2,2.1.6 version, there are struts-spring-plugin-2.1.6 The. Jar (if you are using Spring integration) has this struts-plugin.xml file, and Json-plugin-0.34.jar (as in the case of struts needing JSON support).

Of course In fact, our usual projects are generally speaking Struts.xml configuration files are placed directly in the SRC directory, and then the other configuration files are placed under the same package, and then include these profiles in the Struts.xml file, so struts2 the default loading of the configuration file.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.