Struts 1.2.1 Introduction to New Features (1)

xiaoxiao2021-03-06  84

At present, Struts has been widely used. It is called its default factor standard for Java Web framework. Since APACHE launched Struts 1.1, Apache has modified and upgraded since Apache, where Struts 1.2.1 is this year. Direct results of modifying and upgrading work. Struts 1.2.1 has been made to the errors and instructions in the Struts 1.1, while enhanced, improvement, and has added many new features, these features are worthy of Struts learning, developers' attention. It is recommended that there are conditions to upgrade to Struts 1.2.1, which makes full use of Struts's new features. For the introduction of Struts 1.2.1, you can view it to the Struts official website http://struts.apache.org/userguide/release-notes-1.2.1.html View, you can also go to http://cvs.apache.org/ Dist / struts / v1.2.1 / download. The latest version of the Visual Struts of the JavaWebstudio Development Tool also fully supports the development of Struts 1.2.1 (http://javawebstudio.51.net/).

1, no longer provide GenericDataSource and genericConnection interface

From http://struts.apache.org/userguide/release-notes-1.2.1.html, GenericDataSource and GenericConnection interfaces are no longer available, from downloaded Jakarta-Struts-1.2.1, it has been removed Struts-legacy.jar in Struts1.1, that is, the entire Legacy has dropped. But Struts.jar still retains the DataSourceConfig class. It also retains the DataSources management function.

GenericDataSource is not very necessary, because one is that this DataSource needs to access the data source from the Action class with methods defined in the ActionServlet, and cannot be used from other classes.

There are many ways to customize the custom database connection pool in Struts, where JavaWebStudio (Details can refer to the "Struts Development Instance") custom database connection pool, which is introduced through the web.xml configuration, and Struts1 can also be used. 2.1 Recommended method implementation through the PLUG INS Configuration (plug-in configuration), such as the configuration of Struts comes from Struts-Config.xml:

In addition, Jakarta's DBCP is also a choice.

2, increased data verification components (Validator Enhancements)

· ValidWhen: The ValidTes of Struts supports the ValidWhen rules to implement a data authentication dependent on another data.

INTRANGE: Verified Select-ONE Tags and Radio Labels. EXAMPLE: This Allows Populating Combo Boxes with Valid Choices Plus One Additional Choice with a CAPTION SOMETHING LIKE "Choose One" and a value 0f "-1". Then When The User Attempts To Submit The Form, You CAN Look for the Value Of "-1" and advise if nothing was selected. The client JavaScript value can be used to check all the constraints instead of the interrupt caused by the first error.

· "Required" data verification Processing Checkboxes, Radio, Select-One, and Select-Multiple labels.

· The standard ValidateURL rule checks the validity of the URL.

Designing Complex Validations with Validwhen

A commonly used data verification design is to verify the case of a data domain dependent on another data field (for example, if you want to enter a password, if the two passwords can pass), there is only a certain data field The other data fields are valid depending on effective. The ValidWhen data verification rule provides the above case implementation method.

E.g:

(1)

test

(SendNewsletter == Null) or (* this *! = null)

(2)

test

((ORDERLINES []. partnumber == null) or (* this *! = null)

(3)

test

((HeightinInches> = 60) or (* this * == null)

Unstoppable JavaScript Validations

Forced client JavaScript validation to detect all constraints, instead of interrupts caused by the first error. By setting a new attribute StoponfirstError, the first error setting is completed in the Validator plugin implementation. For example, Struts-Config.xml Settings:

Value = "/

Web

-

Inf

/VALIDATION.XML, /

Web

-

Inf

/VALIDATOR-RULES.XML "/>

3, wildcard

In the action-mapings configuration, a wildcard configuration method, such as the struts-config-registration.xml file in the example of Struts comes with:

PATH = "/ edit *"

Type = "org.apache.struts.Webapp.Example.edit {1} action"

Name = "{1} form"

Scope = "request"

Validate = "false">

Name = "failure"

Path = "/ mainmenu.jsp" />

Name = "success"

PATH = "/ {1} .jsp" />

"/ Edit *" represents all the paths starting with "Edit", {1} represents "*" in the actual form submission (string).

Wildcard mode can contain one or more specialized symbols:

*

No slash ('/') characters.

**

Contains oblique lines ('/') characters.

/ Character

The counterlarm line characters are used for sequential order. / * Match ('*'), and // match ('/').

In Action Mapping and Action Forwards, the serial number n value n can be taken from 1 to 9. All requests.

URI

Wildcard {0} can be used.

At present, the properties of Action Mapping support wildcard are:

· Type

· Name

Roles

Parameter

· Attribute

Forward

Include

· Input

Action mapping will support wildcard properties:

· PATH

4, Maven project file

The Struts project itself has been used to manage Maven. Core JAR and TLDS can use Maven compilation. In the Struts Source Code, we can see the current maven.xml and project.xml file. Of course, Currently, the original ANT compilation file is also the official method of building Struts. It is worthy of concern that Maven will bring great convenience to our project development, detailed information can be referred to http://maven.apache.org/start/USE .html.

5, new Configuration DTD

Configuration 1.1 DTD is not recommended, struts-config_1_2.dtd becomes preferred, Struts-config_1_2.dtd adds two elements and for Struts-Config. Can be used to describe items (or configured) Version number and other information. E.g:

Account Maintenance

]]]]

Allows the Updating of Users Accounts and Subscriptions.

]]]]

6, Session-Scoped ActionMessages

ActionMessages can be saved in the session and cleared after the first use. Save information to the session via Action.SaveMessages (). You can return the saved information via actionMessages.isaccessed (). If you want to clear the information, RequestProcessor.ProcessCachedMessages is checked via IsAccessed ().

This feature is very effective for reuse of information.

7, Ja MailReader

The Struts comes with MailReader Example contains Japanese resource files. Although we don't need Japanese resources, it is very good for us to learn how to implement "international information", and implement the way is very simple, such as the example of itself. JSP has the following language type selection:

  • English

  • Japanese

  • Russian

    Processing in LocaleAction.java:

    Public ActionForward Execute (ActionMapping Mapping,

    Actionform Form,

    HTTPSERVLETREQUEST REQUEST,

    Httpservletresponse response

    Throws exception {

    String language = request.getParameter (language); string country = request.getParameter (country);

    Locale locale = getLocale (request);

    IF (("Isblank (Language) && (! isblank (country))) {

    Locale = New local (language, country);

    }

    Else if (! isblank (language)) {

    Locale = New local (language, "");

    }

    HttpSession session = request.getations ();

    Session.setttribute (globals.locale_

    Key

    Locale);

    String Target = Request.getParameter

    Page

    );

    IF (! isblank (target)) Return New ActionForward (Target);

    Target = Request.getParameter (Forward);

    IF (Isblank (Target) Target = mapping.getParameter ();

    IF (Isblank (Target) {

    Log.warn (locale_log);

    Return NULL;

    }

    Return mapping.findforward (Target);

    }

    .

    8, TILES EL

    TILES tags support JSTL-based Struts EL tag libraries.

    9, Truts-Mailreader

    Struts comes with an example Struts-mailReade to improve. In particular, it adds a Welcome page.

    In Index.jsp, only two lines of code are mainly forwarded to "/ Welcome" forwarding.

    <% @ Taglib Uri = "/ Tags / Struts-Logic" prefix = "logic"%>

    From struts-config.xml, you can see that "/ welcome" Action is WelcomeAction.java file:

    Type = "org.apache.struts.Webapp.Example.welcomeAction">

    The execute () function of the WelcomeAction.java file is as follows:

    Public ActionForward Execute

    ActionMapping mapping,

    Actionform Form,

    HTTPSERVLETREQUEST REQUEST,

    Httpservletresponse response

    Throws exception {

    // setup Message Array In Case There Are Errors

    ArrayList Messages = New ArrayList ();

    // Confirm Message Resources = getResources (request);

    IF (resources == null) {

    Messages.add (constants.error_messages_not_loaded);

    }

    // Confirm Database loaded

    Userdatabase UserDatabase = getUserDatabase (request);

    IF (userdatabase == null) {

    Messages.add (constants.error_database_not_loaded);

    }

    // if there is our errors, forward to yur failure Page

    IF (Messages.Size ()> 0) {

    Request.setttribute (constants.Error_

    Key

    Messages);

    Return Findfailure (Mapping);

    }

    // forward to our success

    Return Findsuccess (mapping);

    }

    The core code is:

    Userdatabase UserDatabase = getUserDatabase (request);

    IF (userdatabase == null) {

    Messages.add (constants.error_database_not_loaded);

    }

    The user checks if the user data already exists.

    10, ACTION package

    Action package is the most modified part, with a large number of modifications,

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

New Post(0)