Struts1.0 Learning Document - Beginner Getting Started

xiaoxiao2021-03-06  74

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 to display the current request error message. The second reset method is used to see some tag libraries from Struts. In fact, there is no Struts. We often take some custom tag libraries to solve the separation of views and code. Of course, in JSP extension tag library applications, there is also a corresponding tag for us to use. However, in order to combine with Struts, we can properly apply the tag library provided by Struts when using Struts. For some tags through the JSP standard, we recommend them here. These tag libctions are described here. Bean Tag Library: First, first introduce the corresponding tag definition in JSP pages before using this mark, for example <% @ Taglib URI = "/ Web-INF / STRUTS-Bean.TLD" prefix = "bean"%>. The method used is, such as . The following is an introduction to the tag library: cookie: Attribute has ID, name, multiple, value, id is unique identifier for cookies on this page, elsewhere can be referenced elsewhere. Equivalent to direct reference with cookie. Name is the corresponding cookie name. Multiple can give any value if this value is defined will return a cookie array of corresponding gauges, if this value is not defined, the value is here a default value, when we call the Cookie here does not exist, its value For our value value. Define: It is equivalent to the JSP tag , attribute has ID, Name, Property, Scope, Toscope, Type, Value. IDs and cookies have played the same role; NAME is the only bean identifier in the corresponding scope; scope will perform corresponding lookups within the corresponding range; Toscope If you find a corresponding bean in Scope, it will be The corresponding bean is established in TOSCOPE; TYPE is the full class path and class.

For example: <% = submitform.getname ()%>, for example: <% = test1_string%> <% = TEST1_VALUE%> Header: Access the header of the corresponding page request by this tag, the specific attribute has ID, Multiple, Name, Value. Specific meaning and similar cookie. For example: <% java.util.enumeration name = (httpservletRequest) Request) .getHeadernames ();%> <% while (names.hasmoreElements ()) {string name = (String) Names.nexTelement ();%> < Bean: header id = "Head" name = "<% = Name%>" /> <% = head%> < / TR> <%}%> include: Attribute has ID, Name, Forward, Anchor, HREF, Transacttion, Page. Description of the property Reference to the corresponding Apache website. For example: <% = index%> Message: Not common, here is ignored. Page: Not common, ignore it here. Parameter: Properties have ID, Name, Value, Multiple. The request parameters and values ​​used to output the client. For example: <% = param1%>
< % = param3%> Resource: Attribute has ID, Name, Input. If the INPUT property is defined as an arbitrary value, the imported resource will return an InputStream object. If you are not defined, the resource will return in a string.

For example: size: used to Cellection or MAP type Data for elemental statistics. The properties are: ID, Collection, Name, Property, Scope. For example: <% java.util.arraylist data = new java.util.Arraylist (); data.add ("first"); data.add ("second"); data.add ("third"); data.add ("FOURTH"); Data.Add ("fiffh"); PageContext.setttribute ("List", DATA, PAGECONTEXT.PAGE_SCOPE);%> struts: Not common, here ignore. WRITE: The property has bundle, filter, format, formatkey, ignore, local, name, proty, scope. Please refer to the relevant website for specific usage. HTML 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-html.tld" prefix = "html"%>. In fact, most of the markers of the tag library can be implemented with HTML tags. The value here is not available to several tags implemented by HTML. Error: Attributes are: bundle, name, property, local. If the above properties are not defined, it will be displayed from all Error. *** error message in the properties file. Bundle, Bonded Error Information Manager, if not defined, the application-level error manager created by Action is default. Name and Property are used to call the error message management bean from the corresponding page to display the error message. Local is an error message localized processor, which is used by default to handle localization in a local manner. In the property resource file, the following information should be included, format the realistic realistic of the error message: Errors.Header all the contents of the error message, you can perform HTML modified errors.footer all error messages, you can make HTML modifications Errors.PREFIX front display information in front of each error message, you can perform HTML modified errors.suffix each error message display information after each error message, you can perform HTML modified Message: property has bundle, footer, header, id, local, message, property, Please refer to the relevant website for specific usage.

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

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

New Post(0)