Struts2 processing result (3) -- dynamic configuration result, struts2 dynamic
Struts2 processing result (3)
-- Dynamic configuration result
1. Use expression syntax
Example:
<Struts> <constant name = "struts. enable. dynamicMethodInvocation "value =" false "/> <constant name =" struts. devMode "value =" true "/> <package name =" package_a "extends =" struts-default "> <! -- This action matches all test _*. request in action mode --> <action name = "test _ *" class = "testAction. testAction "method =" {1} "> <result name =" error "> error. jsp </result> <result> {1 }. jsp </result> </action> </package> </struts>
The existing test_success.action request conforms to the test _ * format. The matching method is the success () method, and the physical view resource mapped by the logical view is success. jsp.
2. The physical view resource is determined by the Action property value.
You can use $ {attribute name. attribute name...} to determine the physical view resource.
Example:
(1) write an Action class, which contains a property name:
Package testAction; import com. opensymphony. xwork2.ActionSupport; public class Test1Action extends ActionSupport {// encapsulated request parameter private String name; // setter and getter Methods public void setName (String name) {this. name = name;} public String getName () {return this. name ;}// logic method for processing the request public String execute () throws Exception {if (name. equals ("jiagushi") {return SUCCESS;} else {return ERROR ;}}}
(2) submit the Action page welcome. jsp
<Form action = "test1" method = "post"> <input type = "text" name = "name"> <input type = "submit" value = "submit"> </form>
(3) physical view resource jiagushi. jsp
(4) configure the struts. xml file
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"><struts> <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="true" /> <package name="package_a" extends="struts-default"> <action name="test1" class="testAction.Test1Action"> <result name="error">error.jsp</result> <result>${name}.jsp</result> </action> </package></struts>
The corresponding physical view resource is found through the Action attribute name.