---
title: "Struts Action 属性的解释"
author: "llhdf"
date: "2010-01-12T17:41:26Z"
tags: []
categories: ["企业架构"]
slug: "struts-action"
draft: false
lastmod: "2010-01-12T17:58:00Z"
id: 568595
url: "https://llhdf.iteye.com/blog/568595"
---

摘录自 Jarkata Struts Live 一书， 留备参考。

 

Action Attributes

 

**Attribute** Description

attribute The attribute specifies the name of the ActionForm that is mapped to a given  
scope. If you do not specify an attribute, the name attribute becomes the value of  
the attribute. Thus, if the attribute is not specified, the attribute defaults to the name  
of the ActionForm.

 

**className**

The className attribute is used to specify custom config object. We will cover  
these in Chapter 10 in more detail. For now, you can replace any config object with  
a custom config object. The custom config object can have additional properties.

**include**

You can use the include attribute to specify a JSP that will handle this request. The  
JSP is the only handler of this request. Using this should be the exception, not the  
norm. This attribute is mutually exclusive with the forward attribute and the type  
attribute, meaning that only one of the attributes can be set.

 

**input**

The input attribute is used to specify the input View for an action. The input attribute  
usually specifies a JSP page that has an HTML form that submits to this action. If  
there are any problems with form validation, then control of the application will forward  
back to this input View. This attribute is optional, but if it’s not included, an  
error occurs when Struts attempts to display validation errors.

**name**

The name attribute identifies the ActionForm that is related to this action. The html:  
form tag uses this name to pre-populate the html form. The request processor uses  
this form name to create and populate an ActionForm to pass to the execute()  
method of the action handler.

path

The path attribute represents the incoming request path that this action maps to.

 

**parameter**

The parameter attribute is similar in concept to servlet init-parameters. Its use is  
application-specific. You can think of it as a general-purpose init-parameter.

roles

The roles attribute is used to specify J2EE security roles that are allowed to access  
this action. If this attribute is present, then only those roles specified in the commadelimited  
list can use this action.

**type**

The type attribute specifies the action handler for this action. You must specify a  
fully qualified class name. The type attribute is mutually exclusive with the include  
and forward attribute.

scope

The scope specifies in which scope (request or session) the ActionForm will be  
placed. The scope attribute defaults to session.

**Unknown**

The unknown attribute is used to specify a default action mapping to handle  
unknown request paths. Obviously, you can only have one of these for each Struts  
config file.

 

**validate**

The validate attribute is used when you want to validate the ActionForm. This is the  
case when you are handling form submissions. By specifying validate equals=true,  
you are causing the request processor to call the ActionForm.validate() method to  
see if there are any field/form validation errors.  
The execute() method of the action will not be called if form validation fails and validate  
equals true. Instead, control of the application would return to the input View.  
You typically set the validate attribute to false, if you want to pre-populate an HTML  
form (e.g., an action that loads a form with form data from a database).

 

转载：[http://space.itpub.net/5256/viewspace-119528](http://space.itpub.net/5256/viewspace-119528)