Struts2 processing result (3) -- dynamic configuration result, struts2 dynamic

Source: Internet
Author: User

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.

 

 

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.