Struts1 Action Attribute Detailed

Source: Internet
Author: User

The specific meaning of some attributes of the action of struts?

A section of the action in struts is defined as follows

<action>

Attribute= "Aaform"

input= "/aa.jsp"

Name= "Aaform"

Path= "/AA"

Scope= "Request"

Type= "Com.yourcompany.struts.action.AaAction" >

<forward name= "AA" path= "/aa.jsp"/>

</action>

What does the attribute and name mean, <forward name= "AA" path= "/aa.jsp"/> What does the name in this name mean and what is forwarded?

Can the action forward multiple JSPs? The right one, the wrong time to another. What should I write?

Second, struts-config.xml documents

/*

<?xml version= "1.0" encoding= "UTF-8"?>

<! DOCTYPE struts-config Public "-//apache Software foundation//dtd struts Configuration 1.2//en" "http:// Struts.apache.org/dtds/struts-config_1_2.dtd ">

<struts-config>

<data-sources/>

<form-beans >

<form-bean name= "UserForm" type= "Cn.hxex.sample.struts.form.UserForm"/>

</form-beans>

<global-exceptions/>

<global-forwards/>

<action-mappings >

<action

Attribute= "UserForm"

input= "/form/user.jsp"

Name= "UserForm"

Path= "/user"

Scope= "Request"

Type= "Cn.hxex.sample.struts.action.UserAction" >

<forward name= "Success" path= "/success.jsp"/>

</action>

</action-mappings>

<message-resources parameter= "Cn.hxex.sample.struts.ApplicationResources"/>

</struts-config>

*/

three, struts in the action attribute detailed explanation

/*

Attribute: Specifies the name of the property used by Actionform to save to the specified context, if the attribute property value is not specified,

Use the Name property value as the property name at the time of the save. The default value for attribute is the Name property value.

Input: This action in the related actionform get user input page, when the Actionform is set to automatically verify the input data, found that the illegal data returned error, will return the page

Name: The names of the actionform used in the current action, with their specific information defined elsewhere in the configuration file

SCOP: Specifies the scope of the Actionform context to be saved. The lifetime of the actionform used in the action can be "request" or "session", and the action will be created at the appropriate time as the lifetime is set.

Validate: If this property is true, its corresponding Actionform validate method is automatically invoked before the action action, which is typically used to validate the data entered by the user

Forward: Set up serverlet or other resources such as JSP pages to handle user requests. If this property is specified, the Type property will lose its effect

Strictly speaking, <forward,include,type> attributes should be used and only one of them should be used. This property is used to jump to another non-action handler.

Unknown: If you set this property to True, you declare that the action will handle all requests that do not find the corresponding action in the entire application, and of course, the unknown attribute of one action in an application system can be set to True

Prefix: Prefix used to match request parameters with bean properties

Suffix: The suffix used to match the request parameter with the Bean property

*/

Related to scope, such as scope= "request", you can get the form object by Request.getattribute (attribute value)

and name corresponds to the definition of the previous form. The name in forward can be said to be an alias of the page, and forwarding is based on the name of the line

You can forward multiple, such as defining two forward success and error

<forward name= "Success" path= "/aa.jsp"/>

<forward name= "error" path= "/bb.jsp"/>

Try

{

......

}

catch (Exception)

{

......

Return Mapping.findford ("error");

}

Return Mapping.findford ("Success");

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.