【文章內(nèi)容簡介】
rs, forwards, or exceptions. The forward, include, and type properties are mutually exclusive. The className property When specified, className is the fully qualified Java classname of the ActionMapping subclass that should be used for this object. This allows you to use your own ActionMapping subclass with specialized methods and properties. See also section . The name property This property specifies the logical name for the form bean, as given in the formbean segment of the Struts configuration file. By default, this is also the name to be used when placing the form bean in the request or session context. Use the attribute property of this class to specify a different attribute key. The roles property This property is a madelimited list of the security role names that are allowed access to this ActionMapping object. By default, the same system that is used with standard containerbased security is applied to the list of roles given here. This means you can use actionbased security in lieu of specifying URL patterns in the deployment descriptor, or you can use both together. The security check is handled by the processRoles method of the Request Processor (). By subclassing RequestProcessor, you can also use the roles property with applicationbased security. See chapter 9 for more about subclassing RequestProcessor. The scope property The ActionForm bean can be stored in the current request or in the session scope (where it will be available to additional requests). While most developers use 8 request scope for the ActionForm, the framework default is session scope. To make request the default, see section . Since Struts Since Struts 200 CHAPTER 7 Designing with ActionMappings The validate property An important step in the lifecycle of an ActionForm is to validate its data before offering it to the business layer. When the validate property for a mapping is true, the ActionServlet will call the ActionForm’s validate method. If validate returns false, the request is forwarded to the resource given by the input property. Often, developers will create a pair of mappings for each data entry form. One mapping will have validate set to false, so you can create an empty form. The other has validate set to true and is used to submit the pleted form. NOTE Whether or not the ActionForm validate method is called does not relate to the ActionServlet’s validating property. That switch controls how the Struts configuration file is processed. The input property When validate is set to true, it is important that a valid path for input be provided. This is where control will pass should the ActionForm validate method return false. Often, this is the address for a presentation page. Sometimes it will be another Action path (with validate set to false) that is required to generate data objects needed by the page. NOTE The input path often leads back to the page that submitted the request. While it seems natural for the framework to return the request to where it originated, this is not a simple task in a web application. A request is often passed from ponent to ponent before a response is sent back to the browser. The browser only knows the path it used to retrieve the input page, which may or may not also be the correct path to use for the input property. While it may be possible to try and generate a default input 9 page based on the HTTP referrer attribute, the Struts designers deemed that approach unreliable. inputForward In Struts , the ActionMapping input property is always a literal URI. In Struts , it may optionally be the name of an ActionForward instead. The ActionForward is retrieved and its path property is used as the input property. This can be a global or local ActionForward. To use ActionForwards here instead of literal paths, set the inputForward attribute on the controller element for this module to true: Since Struts ActionMapping properties 201 controller inputForward=true For more about configuring Struts, see chapter 4. For more about ActionForwards, see chapter 6. The parameter property The generic parameter property allows Actions to be configured at runtime. Several of the standard Struts Actions make use of this property, and the standard Scaffold Actions often use it, too. The parameter property may contain a URI, the name of a method, the name of a class, or any other bit of information an Action may need at runtime. This flexibility allows some Actions to do double and triple duty, slashing the number of distinct Action classes an application needs on hand. Within an Action class, the parameter property is retrieved from the mapping passed to perform: parameter = ()。 Multiple parameters While multiple parameters are not supported by the standard ActionMappings class, there are some easy ways to implement this, including using HttpUtils, a StringTokenizer, or a Properties file (). HttpUtils. Although deprecated as of the Servlet API specification, the HttpUtils package () provides a static method that parses any string as if it were a query string and returns a Hashtable 10 (): Hashtable parameters = parseQueryString(parameter)。 The parameter property for your mapping then bees just another query string, because you might use it elsewhere in the Struts configuration. stringTokenizer. Another simple approach is to delimit the parameters using the token of your choice—such as a ma, colon, or semicolon—and use the StringTokenizer to read them back: StringTokenizer ining = new StringTokenizer((),。)。 int i = 0。 String[] parameters = new String[()]。 while (()) { parameters[i++] = ().trim()。 } 202 CHAPTER 7 Designing with ActionMappings Properties file. While slightly more plicated than the others, another popular approach to providing multiple p