Import this plug-in, the role of the plugin is to replace the Struts.xml principle is not configured, are all conventions
Basic steps
1. New Homeaction, there is an Execute method return success, request home.action so that can execute this
Convention: Home is the Name property value of the action in the previous configuration, and no method name is the default execute
Homeaction→home.action
Studenthomeaction→student-home.action
Package name, the requested action must be placed in the action,actions,strut,struts
Com.kaishengit.action.homeaction→/home.action
Com.kaishengit.action.product.homeaction→/product/home.action
Com.kaishengit.action.product.type.homeaction→/product/type/home.action
2. Add a JSP file. The file name is defined as home-success.jsp, so you can get to the JSP. It must be in a content folder, but you can modify this folder
<constant name= "Struts.convention.result.path" value= "/web-inf/views/"/>
/home.action success→/web-inf/content/home-success.jsp
/home.action input→/web-inf/content/home-input.jsp
/product/home.action success→/web-inf/content/product/home-success.jsp
3. For the request method and the jump way to rely on annotations to achieve
Define another method in Homeaction
@Action ("main") plus annotations, add main-success.jsp request Locallhost/main.action
@Action ("main") public String main () { return SUCCESS;}
Jump
For the params, the odd number represents the key, even the value of the
@Action (value= "Login", results={@Result (name= "Success", type= "Redirectaction", params={"namespace", "/admin", "ActionName", "main"}), @Result (name= "Input", type= "Redirectaction", params={"namespace", "/admin", "ActionName", "Home", "Error", "1001"}) }) PublicString Login () {Admin curradmin=adminservice.login (admin); if(Curradmin = =NULL) { returnINPUT; } Else{putsession ("Curr_admin", curradmin); returnSUCCESS; } }
4. For the main configuration file, Struts.xml constant settings, interceptors, global-result or to configure their own
However, for filters or something, the Convention is a default package. So change it.
<constant name= "Struts.convention.default.parent.package" value= "Basepackage"/>
5. Namespaces
Com.kaishengit.action.product.homeaction→/product/home.action
Can com.kaishengit.action.homeaction→/product/home.action
To annotate @namespace ("product") on the Homeaction
At this time the request arrives the JSP all to be in/content/product/xxxx
Struts2 Convention-plugin