J2EE to success-01-Struts2 configuration, j2ee-01-struts2
Configure the environment
1.Import jar package, official Struts2 website: Http://struts.apache.org/
2.Create Action class to inherit ActionSupport
(ActionSupport class is a tool class that has implemented the Action interface. In addition, it also implements the Validateable interface and provides the data verification function. By inheriting the ActionSupport class, you can simplify Struts 2's Action development.
)
3.Action Configuration:
1) Create the struts. xml configuration file in the src folder.
2). Import the DTD file:
<! DOCTYPE struts PUBLIC
"-// Apache Software Foundation // DTD Struts Configuration 2.3 // EN"
Http://struts.apache.org/dtds/struts-2.3.dtd>
DTD file path: struts2-core-2.3.x.jar/struts-default.xml
3). Create a root node <struts> </struts>
4) create a <package> node in the root node <struts>
<Package> node attribute: name = "package name"
Extends = "struts-default" (fixed value)
Namespace = "/" (do not write, the default value is "/")
5) create a <action> node in the <package> node.
<Action> node attribute: name = "Access name" (action is not required. action must be added during access and cannot be repeated)
Class = "complete path of implementation class ";
Method = "method name" (execute method by default)
The preceding configuration requires a <action> value, which is too cumbersome. Therefore, you can use the wildcard "*".
For example: <action name = "test _ *" class = "full path name" method = "{1}"> </action> (name = "test _ *" can match test_a., test_ B access path. method = "{1}" 1 in curly brackets indicates the first "*" in name)
6). Create <result> under the <action> node (no return value does not need to be configured)
<Result> node attribute: name = "method return value" (if return value exists, the data type must be String)
Type = "dispatcher" (set forwarding or redirection. The default value is forwarding dispatcher. Redirection: redirect)
Create a method without return values: method without return data type (void)
02 return Action. NONE (NONE = NULL)
Example: <result name = "success" type = "dispatcher"> index. jsp (jump to the page) </result>
7). Global result page Configuration:
<Global-results>
<Result name = "success">/loding. jsp </result>
</Global-results>
4.Configure a filter in web. xml
<! -- Filter-class in eclipse use the shortcut key: Ctrl + Shift + T input: StrutsPrepareAndExecuteFilter to find its path -->
<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> *. action </url-pattern>
</Filter-mapping>
The above is how to configure the Struts2 configuration file!