I wrote my summary for the first time and found that it was easy to understand and make it easy for others to understand the difficulties and errors. please correct me. Thank you for making a brick. Haha ~~
The well-known struts2 is a well-designed MVC Framework-you can use it in a non-intrusive way if you want. Struts2 is configured in a variety of ways: the traditional struts. XML, and of course the legendary Convention plugin.
It should be noted that the use of wildcards in struts. XML is the problem of wildcard.
Wildcards can be used to match the name attribute of action, the name attribute of result, and the name attribute of method. As long as your Code complies with certain specifications, you can use wildcards according to your specifications, the configuration quantity can be greatly reduced.
For example:
Struts. XML has the following code:
<Action name = "Notes _ *" class = "com. tding. NT. web. action. notesaction "method =" {1} "> <br/> <result name =" {1} ">/WEB-INF/Notes _ {1 }. JSP </result> <br/> </Action>
This configuration is too simple to work. For example, if I request notes_xxx.action, struts2 will automatically help us match the xxx method and XXX. jsp page.
With this configuration, if you want to add the delete method in notesaction and want it to jump to notes_delete.jsp, you only need to add the method and page, without any other configuration.
Everything looks perfect, but there is a potential problem:
The code for notesaction is as follows:
Public class notesaction extends actionsupport {<br/> ......... Other code ......... <Br/> Public String list () {<br/> return "list"; <br/>}< br/> Public String add () {<br/> return "add"; <br/>}< br/> Public String save () {<br/> notemanager. add (Note); <br/> addactionmessage ("add successfully"); <br/> return list (); <br/>}< br/>
For example, when I request notes_save.action, an exception is thrown:
No result defined for Action com. tding. CNT. Web. Action. notesaction and Result List
After analysis, the cause of the error is as follows:
When I call save. Action, Struts. XML is parsed as follows:
<Action name = "notes_save" class = "com. tding. NT. web. action. notesaction "method =" save "> <br/> <result name =" save ">/WEB-INF/notes_save.jsp </result> <br/> </Action>
It can be seen that only one result is defined, and the Save method calls the list method and returns the "list" string as the result. At this time, the list is an undefined result, therefore, an error occurs.
The solution is as follows:
1) define the global result list
<Global-Results> <br/> <result name = "list">/WEB-INF/notes_list.jsp </result> <br/> </Global-Results> <br/> <action name = "Notes _ *" class = "com. tding. NT. web. action. notesaction "method =" {1} "> <br/> <result name =" {1} ">/WEB-INF/Notes _ {1 }. JSP </result> <br/> </Action>
2) cancel the wildcard in the result
<Action name = "Notes _ *" class = "com. tding. NT. web. action. notesaction "method =" {1} "> <br/> <result name =" list ">/WEB-INF/notes_list.jsp </result> <br/> <result name =" add ">/WEB-INF/notes_add.jsp </result> <br/> </Action>
Summary: Error Type: no result defined for Action XXX. action and result YYY are thrown when Wildcards are used in struts2. Exception