STRUTS2 Authority Guide

Source: Internet
Author: User
Tags html form html tags

STRUTS2 authoritative Guide to introduce, and combined with the author before this also used WebWork and struts1, but still more familiar with the webwork, fortunately, Struts2 is close to webwork, so the study cost is relatively low, struts2 the benefits do not say, Let's talk about differences.

1, relative Struts1, no Formbean, the form code does not need to use struts to provide HTML tags, the general HTML form tag can also be used, coupled learning costs are much lower. Think of Struts1, without its own HTML tags, form elements can not be injected, in addition to action, you have to write another formbean, and can only inject Java basic data types, code redundancy too much, configuration too complex;

2, before the use of struts1, in addition to the use of the label is not accustomed to, is the object of the property injected, Struts2 finally can use (object. properties) of the way to inject, example:< INPUT name=picture.id>

3, the action does not inherit any parent class, also does not need to implement any interface, is equivalent to a simple object, this is higher than the webwork. The parameters passed from the page and from the action to the page are all done through the interceptor. Here are some common ways to implement the action, and of course there are other ways to look at the API.

1 The action can implement any interface without inheriting any of the parent classes, without coupling with the servlet API, and without coupling with the STRUTS2 API can be just an ordinary pojo, containing the getter and setter methods and the Execute method. The STRUTS2 interceptor mechanism is used to parse the request parameters of the user and assign the request parameters to the corresponding attributes of the action. However, this action class does not interact with the JavaBean and does not display the results of the business logic operations to the client.

2 interface action, this interface defines only the Execute method and 5 standard string constants: Success\none\error\input\login, which simplifies the return value of the Execute method.

3 Inherits Actionsupport,actionsupport is a tool class, has implemented the action interface, also implements the Validateable interface, provides the data verification function. You can look at the API documentation specifically. Overrides the Validate method defined in the Validateable interface and, if the form is entered incorrectly, adds an error to the fielderrors of actionsupport and outputs it through the OGNL expression. The Validate method executes before the Execute method, data checksum error, and the request is forwarded to the input logic attempt. Of course, you can not rewrite the Validate method, use the configuration file for data validation. In addition, Actionsupport provides the ability to internationalize information gettext.

4, the list element type injection, WebWork provides the array type input, but the object list's injection is not good. To give a simple example, upload a picture, the user may upload one at a time, but also may upload the N-Zhang, the number of uncertain objects.

1) Private list< picture> picturelist; Picture Object list
picture 1< input name=picturelist[0].description>
picture 2< input Name=picturelist[1].description >
output:<? xml:namespace prefix = ww/>

< ww:iterator value= "picturelist" >< ww:property value= "   Description "><

/ww:property></ww:iterator>
2) Private string[] description; String array
description 1< input name=description>
description 2< input name=description>
output:< ww:iterator "description" >< ww:property><

/ww:property></ww:iterator>

WebWork the first way is not automatically injected, but the second can; now struts2 two ways can be achieved, convenient!!

5. Struts tags only recognize standard getter and setter methods, and for Boolean properties, Eclipse automatically generates get and set methods that are not standard. For example, when a Boolean attribute is defined as isxxxxx, the getter and setter generated by Eclipse is Setxxxxx (boolean isxxxxx), Isxxxxx (), Instead, the Struts2.0 Converter uses Setisxxxxx (Boolean isxxxxx), Getisxxxxx (), or a Boolean property named Xxx,eclipse generated method of isxxx () and Setxxx (Boolean xxx), while the struts2 user is getxxx (), Setxxx (Boolean isxxxxx). But eclipse automatically generates get, set methods, Ibatis can be injected automatically, and standard gets, set method Ibatis can also be injected.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.