Reading notes - Jakarta Struts Programming

zhaozj2021-02-16  63

1. Forwarding and Redirect: Any object stored as a request attribute will disappear before the redirect is reset. The object can be stored in the request during forwarding and sent to the next resource.

2.? Struts1.1 can have multiple ACTIONSERVLET

3. About the initialization parameters of web.xml in Struts1.1

(1) Config: The path to the context of the default Struts profile. The default is /Web-inf/Struts-Config.xml, which is used as the default application.

(2) config / sub1: You can use the config / value and subroutine prefix to specify additional subroutines. Init-param is called CONFIG / SUB1, the value should be Web-info / struts-sub1-config.xml. This will notify The Struts configuration file is added to the subroutine SUB1. You can declare multiple subroutines as needed.

(3) Debug: Specify the details of the servlet to control the amount of information recorded, default = 0

(4) Detail: Detail debugging amount, default = 0; DEFAULT = 0;

(5) Converthack: This is the value in struts1.0. If true, any ActionForm using the Java wrapper class type will be set to NULL.

3. Configuring the struts program Controller for 1.1, Controller is a new element. Prior to the 1.1 version, the ActionServlet contains the controller's function, and you have to extend this feature, but the Struts in version 1.1 has moved most of the controller functions to the RequestProcessor class. The ActionServlet is still accepting requests, but it will request a request to assign an instance of the RequestProcessor, which allows you to fully fully equip the processor class and modify its functions. 4.Message-resources Element 5.plug-in element 6. The role of the controller: can handle security, international, and logging services. (1) Intercept customer request (2) Map each request to a specific business operation (3) to collect results from the business operation and make them valid for customers (4) to determine as the customer according to the results of the official state and business operations. view

7.action instance: Action instance should be thread secure, so you only create a separate instance for each Action class in your application. All customer requests share an instance and can simultaneously call the Excute () method.

Design Criterion of Action Class:

Role: Verify the input value, process the relevant control operation, such as saving a record to the database, updating the object of the next page, such as saving the object in the session. Returns an ActionForward object to respond to the current user's request, and so on.

Can handle services such as security, internationalization, and logging.

(1) Intercept customer request

(2) Map each request to a specific business operation

(3) Collect results from business operations and make them valid for customers

(4) Determine the view to the customer according to the results of the official state and business operation

Cause: Since each Action class only creates an instance, all customers request to share an instance and can call the execute () method at any time.

Design Guidelines:

The concept of multi-threaded environments when designing the Action class: must guarantee the thread of the Action class. There are several principles for reference:

(1) Use only local variables. Do not use instance variables of objects to store customer specific status. If you want to use a specific instance variable to store status information, it should not be a customer or request unique. If you create an org.apache.commons.logging.log type instance variable store information in the logger, this is ok because it is a thread.

(2) Saving resources: As a general guidelines, some problems may be brought to the request of the rare resources and save it in the same user. For example, if the JDBC used in the program and you assign a separate JDBC to each user So the Web site crashes or other cases, you can have some problems. It is best to use the "Pool" concept and release these resources before the controller is jumped to another page. Even if you call Bean The method throws an exception, you will also do this. (2) .don n't throw it, catch it! For anomaly in ACTON, you must capture it, and record the log turning to an error, but cannot be Among them, it will throw out. In particular, "Throw new java.lang.unsupportedOperationException" in JBuilder is automatically generated, "Error Occured In Action."); "Be sure to write after the specific code It is deleted.

(3). To avoid too long and too complicated Action class, if you collect too much logic in the Action class, then this class is difficult to understand, maintain, and it is impossible to reuse it. It is best to deal with some of the following logices such as security, internationalization, logging, page jump, and other re-complex logic, it is best to add another class to handle, by ACTION transfer.

(4). In some routines that come with Struts, the more complex logic is placed in the action, which is not imitated. Pay attention to some of the official routines.

Attribute

The request or session is dominated by the domain property name, and the form bean that the action can be accessed. There is only a value in the Name property specified in the Name property. This attribute is optional without default. If this attribute and the NAME property contain a value, this property has priority.

Classname

Configure the configuration of the configuration bean for action information. If no value is specified, the org.apache.struts.Action.ActionMapping class is the default class. This attribute is optional.

Forward

To the application related to the application you want to go to the servlet or JSP resource rather than instantiation or call the Action class. Forward, Include and Type properties are mutually exclusive, and only one must be explicitly specified. This attribute is optional. Org.apache.struts.Actions.ForwardAction can be used to get the same behavior.

Include

To servlet or JSP resource related paths, will be referenced with the response without reselecting and calling the Action class. Forward, Include and Type properties are mutually exclusive, and only one must be explicitly specified. This attribute is optional. Org.apache.struts.Actions.InCludeAction can be used to get the same behavior.

INPUT

When you encounter a verification error, pointing to the control will return to the application related path to the input form. If the Name property is specified, it is necessary, if the NAME property is not specified, then this attribute is not allowed.

Name

The name of the FORMBEAN related to this action must be one of the previously defined FormBean elements of the Name property. This attribute is optional and there is no default.

Path

Request the application related path to "/" begins. If you use an extension map, there is no extension of the file name. In other words, this is the name of the action, such as / addtoshoppingcart. This value is required, which may be more referred to as "name" because it determines the name of the operation.

Parameter

The configuration parameters used in the usual purpose can be used to pass additional information from the action mapping selection to the action example. The core frame package does not use this value. If you provide a value here, you can get it by calling the getParameter () method when an actionMApping is passed to an Execute () method. Prefix

Used to match the request parameter name with the Form Bean property name. For example, if all attributes in the Form bean start with "pre_", then you can configure the prefix attribute so that the request parameter will match the ActonForm property. A value can be provided here only when the Name property is specified.

Roles

The secure role name list defined by the comma, allows calls to call the action. When requesting processing, RequestProcessor checks if the user has at least one of the values ​​identified. This attribute is optional.

Scope

Whether requested or session, this property is used to identify the scope of the placement form. This attribute can only be specified when the Name property occurs. The default is Session

SUFFIX

Used to match the request parameter name with the Form Bean property name. For example, if all requests in the form bean are ending "_foo", you can set up the suffix property to make the request parameters match the ActionForm property. You can only provide a value here only when the Name property is specified.

Type

Extended the fully qualified Java class name of the org.apache.struts.Action.Action class. This property is used to process requests when the properties of the Forward and include are specified. Forward, Include and Type properties are mutually exclusive, and only one must be explicitly specified.

Unknown

A Boolean value for explaining whether or not the Action is configured to be default. If true, then the action can handle any requests that are not processed by other ACTION. Each application only one action mapping can set this attribute value to True. This attribute is optional, the default value is false. This is a great place to establish a default action to capture any invalid URL entered by the user. This attribute name is or called "default" better.

Validate

The Boolean value is used to illustrate whether the validate () method of the FORM bean specified by the Name property should be prioritized, so that the action of the action () method can be called. This property is optional and the default is TRUE.

8.actionform:

ActionForm is a container for HTML form data that may be saved in Session (default) or Request. If ActionForm is in Session, there is a point that you must be clearly: to call its reset method before using it. For the design and development of ActionForm, there is a criterion:

(1) ActionForm itself does not have a specific method. An ActionForm bean can only have getter and setter methods, do not include business logic.

(2) Actionform object also provides a method of data checking. You only need to implement this test method and provide the error information provided in the resource. Struts automatically checks the correctness of the data. Of course, this check method can also be ignored, and in other places, if they are checked, they are checked.

(3) Define an attribute with a getter and a setter method for a field in each form bean. Its method should comply with JavaBean's specifications. Provides tools that use JBuilder to define, which improves efficiency and reduces the chances of error.

(4) The buttons and other controls in the form must also define an attribute. This helps to find that button or control when the form is in advance. It is not to pay attention to: FormBean is just a data entity that reflects form data, not data bean. (5) You can use the ActionForm as a firewall between HTTP and action, using the Validate method to ensure that all requests are exist. And contain a reasonable value. A calibration failed ActionForm will not be submitted to the action.

(6) To remember an instance of a bean in your form, use the relevant properties. For example, you put a "customer" bean in your form, where the customer.name will be mapped into a Customer.getName () and Customer.setName (String Name) method. This can be referred to the relevant JSP and TAG LIB development manual.

(7) !!!! WARNING: If you put a bean instance in your form, you will consider its visibility requirements. You can accept a URL string to set the value by one URL string. Therefore, it is necessary to consider visibility, which can only be seen, and the specific control visibility method is to control the visibility of its Getter and Setter method. Under the visibility package, it is also possible to provide a related filter to ensure that the attribute value of the running period is not set to be an inappropriate value.

The properties of the Form-bean element:

ClassName If you don't want to use the title configuration bean, rog.apache.struts.config.formbeanconfig, you can specify your own class. It must be an extension of the FormBeanconfig class. This attribute is optional, if not specified, the frame package will use an instance of the FormBeanconfig class. Dynamic If the class identified by the Type is org.apache.struts.Action.DynaActionform instance or its subclass, this value should be set to true, otherwise false. This attribute is optional, its default value is false. It has been negated, the framework will now automatically determine it. Name is used to reference the unique identifier of the bean throughout the frame package, which is required and is unique in the subroutine. Type inherits the fully qualified Java class name for the Struts Actionform class. If the address is specified as org.apache.struts.Action.DynaActionform, then Struts will dynamically generate an instance of DynaActoinform. This attribute is necessary.

Form-property element properties:

ClassName If you don't want to use the standard configuration bean org.Apache.struts.config.formpropertyConfig, you can specify your own class, which is not required. INITIAL indicates a string of the attribute initialization value. If not specified, the original value will be initiated to 0, and the object will initialize to NULL. This attribute is not required. Name This property describes the attribute of the property of the JavaBean property name. This attribute is necessary. TYPE This bean property implements the method class fully qualified Java class name, the later option "[]" indicates that the attribute is indexed. This attribute is required.

9 Properties about exception processing EXCEPTION elements:

Classname

Configuration Bean implementation of the control exception information. If specified, must be a subclass of org.Apache.struts.config.exceptionconfig, if not specified, its default value is ExcePtoInConfig.

Handler

Treat a fully qualified Java class name for processing an exception handler. If no value is specified, you will use the default org.apache.struts.Action.exceptionHandler. If specified must be the subclass of the ExceptionHandler class. Key

The message key specified for the subroutine in the resource package. ActionError instance uses this value.

Path

The path turned to the path of the application when the exception occurs. This attribute is optional, if there is no specified value here, the frame package will be set by default to an input property mapped by ACTION.

Scope

Store the SCOPE level identifier of the ActionError instance. The attribute value must be a request or session. This attribute is an option, if not specified, the default value is Request.

Type

The fully qualified Java class name of the abnormality to be processed is required because the frame package cannot assume an exception, and it needs to be determined.

Bundle

Identify the resource binding servletContext property of the Key property of this element.

转载请注明原文地址:https://www.9cbs.com/read-18584.html

New Post(0)