Struts2 Framework Learning (I.)

Source: Internet
Author: User

Struts2 Framework Learning (I.)

1,Struts2 Framework Introduction

The STRUTS2 framework is an MVC process framework that is suitable for tiered development. Framework application implementations do not rely on servletsand use a large number of interceptors to handle user requests, which are non-intrusive designs.

flow principle of the 2,STRUTS2 framework


1) request to reach the Filter Center Controller first

2) then create the proxy class for the Action

3) Store each service in the interceptor, execute the interceptor and then execute the action class , invoke service, and then call DAO

4) Get the result string, create the results object

5) turn to the corresponding view.

The program flowchart is as follows:

3. Use of frames

Framework for us to do the encapsulation, use it to follow the steps, configure a few XML files on the line pull.

1) Import jar Package

2) Copy struts.xml file

Place the copied configuration file under the root directory src. The Struts.xml file is primarily configured with the request path corresponding to the action class, as well as the result jump path strength.

[HTML]View Plaincopyprint?
  1. <? XML version= "1.0" encoding="UTF-8" ?>
  2. <! DOCTYPE Struts Public
  3. "-//apache software foundation//dtd Struts Configuration 2.0//en"
  4. "Http://struts.apache.org/dtds/struts-2.0.dtd">
  5. <struts>
  6. <package name="Example" namespace="/example" extends= "struts-default">
  7. <action name="HelloWorld" class="struts2.action.HelloWorldAction">
  8. <result name="Success">/success.jsp</result>
  9. </Action>
  10. </Package>
  11. </struts>

Code Description: Access/example/helloworld.action corresponding to execute struts2.action package under the Helloworldaction class, by default executes the Execute method in the class, if you want to specify a method, you need to < The action> tag adds the method attribute to the;<result> label configuration result jump path. A jump is made to match the name value in the result label according to the string string returned by the method in the action class.

3) Configuring the core controller in the Web. xml file

[HTML]View Plaincopyprint?
    1. <!--configuration Framework Core Scheduler--
    2. <filter>
    3. <filter-name>struts2</filter-name>
    4. <filter-class>org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilter</ filter-class>
    5. </filter>
    6. <filter-mapping>
    7. <filter-name>struts2</filter-name>
    8. <url-pattern>/*</url-pattern>
    9. </filter-mapping>

Struts2 Framework Learning (I.)

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.