Struts Development Help Document 1. Overview Struts is based on some currently relevant standards (servlet, XML ...), providing an open source project for development framework, because we develop the complexity of Web applications with the system The complexity requirements are increasingly complex. Especially in code reuse, code transplantation, posture, etc., many duplication, maintenance difficulties, etc. Struts This framework encourages us to apply Model2's MVC development model. Of course, we don't have to fully comply with it based on its development. When the current Struts is relatively stable release 1.0, there is already 1.1 test development version. To learn more about, please visit www.apache.org/struts. Second, the overall structure overview can find graphics about the MVC structure and Struts structure everywhere. Here I will not describe the structure chart. Struts will be described only for the basis for the relevant standards for J2EE Web applications to describe the entire framework. In fact, the Struts framework is entirely based on J2EE related technologies and standards. Struts provides a servlet to the model of the client to transfer to the background of the background. It provides a mapping of requests and processing classes in order to separate each part can be separated. The entire class map is completely from the class reflection and corresponding request filtering technology from Java technology. Realize the connection of the corresponding view and model by tag extension. The whole structure is like this, please don't think more. Third, the detailed development note ¨ The controller is implemented by struts, and the class is org.apache.struts.Action.ArtionServlet. Developers only need to configure the corresponding class maps in the web.xml file. Please refer to the following description: Here is only the initialization parameter Application in which it is: The name of the property file is configured here ApplicationResources, of course we can modify, but the path of the file must be a web-inf / class / or corresponding package directory. ¨ Model About Struts Many articles are described accordingly, divided into system status models and business logic. These are important to understand the Struts, the application of Struts is important. But here I only introduce two important classes, one is the corresponding request data maintenance Java Bean class, and the other is a common class that performs corresponding request processing. The former is required in Struts to inherit the org.Apache.Struts.Action.Actionform class, which is provided by Struts, which needs to inherit the org.apache.struts.Action.Action class, which is also provided by Struts. In the first implementation bean, various attributes must be corresponding to the various field names requested by the customer, the purpose is to complete the automation of the customer request data, we understand this practical thing: ie, as long as we meet this Requirements, Struts automatically populates the client's request in the corresponding JavaBean. And we can overreload the corresponding two methods to implement the checksum resets of each field of JavaBean to ensure our requirements.
These two methods are public ActionErrors validate (ActionMapping actionMapping, HttpServletRequest httpServletRequest) and public void reset (ActionMapping actionMapping, HttpServletRequest httpServletRequest), the processing returns a corresponding error object in the first method, the object is automatically added to an error In the manager, we can directly call in the code of the layer, such as using the tag
For example:
For example:
Logic Tag Library: Use this tag library First to introduce the tag library definition file in the corresponding page, such as: <% @ taglib URI = "/ Web-inf / struts-logic.tld" prefix = "logic"%>, specific The tags are: Empty: Attribute has Name, Property, Scope. Equal: The property has cookie, header, name, parameter, proty, scope, value. Among them, Cookie and Header, Parameter are used independently. Name and Property, Scope are used in conjunction with Beans in the system. If it is a simple parameter in the system, you can use Name and Scope. Forward: Attributes only name. GreateRequal: The property is the same as Equal. Greaterthan: The property is the same as Equal. Lessequal: The property is the same as Equal. Lessthan: The property is the same as Equal. Notempty: Property is the same as EMPTY. Match: attributes, like Equal. NOTMATCH: The property is the same as Equal. Notequal: Properties, like Equal. NOTPRESENT: Properties include Coolie, Header, Name, Property, Parameter, Scope, Role, User. Present: Like NOTPRESENT. MessageNotpresent: Properties have Message, name, property. MessagePresent: Like MessageNotPresent. Iterate: Properties include Collection, ID, INDEXID, Scope, Name, Property, Length, Offset, Type. ¨ Database Access, Struts provides its own data source configuration and manager, but the corresponding management methods in version 1.0 and 1.1 are different. Here I strongly recommend using the relevant data source configuration in J2EE. File Upload, Struts provides class org.apache.struts.upload.formfile, as long as we provide this type of fields in ActionForm, then processes in the action. ¨ Simple BBS implementation sample code (based on struts1.0), please ask me to send me an email luopc@edu-edu.com.cn. Reprinted from: http://www.javaresearch.org/article/showArticle.jsp? Column = 23 & thread = 7816