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?
- <? XML version= "1.0" encoding="UTF-8" ?>
- <! DOCTYPE Struts Public
- "-//apache software foundation//dtd Struts Configuration 2.0//en"
- "Http://struts.apache.org/dtds/struts-2.0.dtd">
- <struts>
- <package name="Example" namespace="/example" extends= "struts-default">
- <action name="HelloWorld" class="struts2.action.HelloWorldAction">
- <result name="Success">/success.jsp</result>
- </Action>
- </Package>
- </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?
- <!--configuration Framework Core Scheduler--
- <filter>
- <filter-name>struts2</filter-name>
- <filter-class>org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilter</ filter-class>
- </filter>
- <filter-mapping>
- <filter-name>struts2</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
Struts2 Framework Learning (I.)