Struts related

xiaoxiao2021-03-06  46

The three associated relationship request forwarding of the Web component is transparent to the client, and the information in the request is held. Request Redirect Repaut to New URL Contains (Include)

Solve parallel development: 1, support for multiple profiles (actually to merge, may cause Forward conflicts) 2, the module supports ModuleConfig's XXXConfig to the module XXXConfig, formBeanconfig (consider the forwarding between modules: Forward or SwitchAction)

Every time you write an application with inheritance baseAction and baseform, of course, BaseAction is best to inherit the LookUpdispatchaction, Baseform is best inherited ValidatorActionform

Built-in Struts Action FORWARDACTION No FORMBEAN, Direct Forward to JSPinCludeActionDispatchactionLookUpdispatchaction // An Action Multiple Operation SwitchAction // Multi-Memorial Use TOKEN to resolve repetition

Struts' exception handling mainly captures business logic abnormalities in the business layer (best to customize), the business layer to capture the exception of the DAO layer (throw a unified DataException exception, it is best to write log)

Struts extension (Plugin): Initialization, such as Hibernate

The advantages and disadvantages of taglib (learning must be difficult, Web Designer may not be familiar)

The use of resource files (multi-language, use NATIVETOASCII to convert non-ASCII text to UTF-8) All HTML and JSP's ContentType is set to UTF-8, and a FILTER is added, and the corresponding encoding ActionMessage and About resource files (MessageResources) ü If there is no configuration, the default is the ApplicationResources.properties under the web-inf / class directory.

ü If you work in Struts-Config.xml, you specify the default resource file as YYY.Properties under the web-inf / class / xxx directory.

ü If struts-config.xml made , specify the default resource file as YYY.Properties under the web-inf / class / xxx directory, However, specify the reference bundle "RES" so that the Struts Validator client verification can not find the relevant resources.

ü can configure multiple resource files

Treatment of shared constants (constant's constants.java file)

Solve an actionform problem (more pages, rapid increase, maybe the same type page field will appear in different actionform, and verify code repetition) 1, a module or related page checks to an actionform (polymerization, multiplexer difference) 2, DynaActionform (configuration Configuration in the file, actually exist in a HashMap class object, so enforce the conversion when GET is enforced) Action Note 1, the view level (form) verification (can be used in JavaScript) in the actionform (if the input is not empty, e- Whether the mail format is correct, etc.), business-related verification is in action (may involve model), which can get the maximum actionFrom Reuse 2, and claim that the service logic is separated into a separate JavaBean, and Action is only responsible for error handling and Process control, and do not reference any objects related to the web application in the JavaBean executing business logic, such as request, response, etc., which should be converted into normal Java objects (such as transfer business value object vo), you can refer to PetStore WAF frame.

The form bean is a data representation of the web layer, he cannot be passed to the business layer; PO is a persistent layer data representation, in a particular case, such as Hibernate, he can replace VO in the business layer, but no matter whether Po is also VO Control is limited to the business layer, the Control that reaches the Web layer must not be spread to the view. Data conversion between Form Beans and POs is to drip in Action. However, due to the powerful function of Hibernate, such as dynamically generating PO, PO's status management can be separated from Session so that in the J2EE framework for applying Hibernate, PO can act as VO, so we will consolidate PO and VO, collectively referred to as PO

The exception handling mechanism for the Struts framework includes an ActionServlet class, the RequestProcessor, ExceptionHandler class processing exception mechanism declares (generally global exception, such as login fail, etc.) Specify who is specified in the configuration file to process an exception thrown in the action, need to implement ExceptionHandler subclass, override the Execute method.

Commons logging interface

The so-called Commons logging interface refers to the use of logging and log specific implementation, and specifies the specific use log implementation by configuration files. This way you can use the log function through a unified interface in Struts 1.1, without the specific use of which log implementation, a bit similar to the JDBC. The log implementations supported in Struts 1.1 include: log4j, JDK Logging API, Logkit, NOOPLOG, and SIMPLOG.

You can use the Commons logging interface as follows (specific log implementation in commcts-logging.properties) (you can refer to many of the Struts source):

Package com.foo; // ... import org.apache.commons.logging.log; import org.apache.commons.logging.logfactory; // ... public class foo {// ... Private static log log = Logfactory.getlog (foo.class); // ... public void setbar (bar bar) {if (log.Istracenabled ()) {log.trace ("setting bar to" bar);} this.bar = Bar;} // ...} The easiest way to open the log function is to add the following two files in the web-inf / class directory:

Commons-logging.properties file:

# Note: The Tiles framework now uses the commons-logging package to output different information or debug statements Please refer to this package documentation to enable it The simplest way to enable logging is to create two files in WEB-INF / classes:.. # Commons-logging.properties # org.apache.commons.logging.log = org.apache.commons.logging.Impl.SIMPLOG # Simplelog.properties # # Logging detail level, # # # m one of ("trace", "debug "," info "," warn "," error ", or" fat "). # org.apache.commons.logging.simplelog.defaultlog = traceorg.apache.commons.logging.log = Org.Apache.commons.logging .impla.simplelog

Simplelog.properties file:

# Logging detail level, # must be one of ("trace", "debug", "info", "warn", "error", or "fat"). Org.apache.commons.logging.simplelog.defaultlog = Fatal

Here we use the log implementation is simplelog, you can specify log details at the Simplelog.properties file: Trace, Debug, Info, Warn, Error and Fatal, from Trace to Fatal Error Levels, and output log information There are fewer and fewer. These levels are in one or one in the ORG.APache.commons.logging.log interface. These levels are contained back, that is, the front level contains information of the rear level.

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

New Post(0)