1. Org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter Preparation and operation
2.
<filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</ Url-pattern> </filter-mapping>
url-pattern contract cooked into only write * *, not required to write *.action
3.
<package name= "Default" namespace= "/" extends= "Struts-default" > <action name= "Hello" > < result> /hello.jsp </result> </action> <span style= "White-space:pre" > </span></package>
Namespace= "/" and the access to the path meaning corresponding;
/hello.action
Interviewed for action. gave us the result of our result.
The default action can be omitted.
4. Associated structs source code and Java docs
Jar file Right-click->properies->java Source Attachment
Set source code
D:/program Files/struts-2.1.6/src/core/src/main/java
Javadoc documentation
File:/d:/program files/struts-2.1.6/docs/struts2-core/apidocs/
To set the XML hint:
A) window–preferences– search Catalog–add
B) Select key type as URI
c) key:http://struts.apache.org/dtds/struts-2.0.dtd
d) Location: the corresponding DTD file. Located in the Struts-core package, unzip the open. Specify the appropriate location, such as D:/program files/struts-2.1.6 \LIB\STRUTS2-CORE-2.1.6\STRUTS-2.0.DTD
5. Structs Implementation Mechanism
Find the filter Dofilter method , WebApplication, Web. XML, URL---HTTP request, client--Tomacat-> ;
<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>
--Struct.xml to find the corresponding action, find the appropriate result, feedback result, request Forwad to the destination file
<package name= "Default" namespace= "/" extends= "Struts-default" ><action name= "index" ><result>/ Index.jsp</result></action> </package>
6, namespace decided the action of the access path, the tacit feel "". Action that can receive the full path
Namespace can be written as/, or/xxx, or/xxx/yyy,
The corresponding action access path is/index.action,/xxx/index.action. or/xxx/yyy/index.action.
Namespace it is best to also use a module to name
<constant name= "Struts.devmode" value= "true"/> <package name= "front" extends= "Struts-default" Namespace= "/front" > <action name= "index" > <result>/Namespace.jsp</result> < /action> </package> <package name= "main" extends= "Struts-default" namespace= "" > < Action name= "index" > <result>/Namespace.jsp</result> </action> </package >
Struct.xml Analysis
Package role: To avoid the name of action and conflict issues;
namespace= "/front", must start with a slash, namespace preferably also use a module to name;
not writing namespace, equivalent to Namespace = "", means that only the action is found and all is given to
namespace processing.
Process: First find the action under the corresponding path to match. If not, look for an action that namespace empty.
If the action is not found, an error will be given;
7, the return of the detailed view can be determined by the user-defined action;
The detailed method is to find the corresponding configuration item according to the returned string, to determine the content of the view;
<constant name= "Struts.devmode" value= "true"/><package name= "front" extends= "Struts-default" namespace= "/" ><action name= "index" class= "Com.struts2.front.action.Index" ><result name= "Success" >/ Actionintroduction.jsp</result></action> </package>
the implementation of the detailed action can be a common Java class. There is a public String execute method that can be implemented
Action interface;
Package com.bjsxt.struts2.front.action; Import com.opensymphony.xwork2.Action; public class IndexAction1 implements Action {@Overridepublic String execute () {return "Success";} }
Configuration Analysis:
<class= "Com.bjsxt.struts2.front.action.Index" >
Struct.xml, find the appropriate class-a instantiation object-run the appropriate execute () method
Run the process:
Read XML---action is class, find class object (each visit must be a new object)
When class is not configured, the default class is Actionsupport.
Actionsupport Source code
Public String Execute () throws Exception { return SUCCESS;}
The most frequently used is inherited from Actionsupport. The advantage is the ability to directly use the Struts2 encapsulation method.
Package com.struts2.front.action; Import Com.opensymphony.xwork2.ActionSupport; public class IndexAction2 extends Actionsupport {@Overridepublic String execute () {return ' success ';} }
Reason: Actionsupport has encapsulated a lot of methods that can be called directly, and can be used directly in subclasses.
The above is based on the granite soldiers gathered from the teacher's tutorial.
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
"Web Development Learning note" STRUCTS2 Action Learning Notes (one)