Struts2 Study Notes (1) configuration of the Struts2 configuration file

Source: Internet
Author: User

1. Configure the web. xml file. In Struts2, the struts framework is started through Filter. The Filter configuration in web. xml is as follows:

<Filter> <filter-name> struts2 </filter-name> <filter-class> org. apache. struts2.dispatcher. ng. filter. strutsPrepareAndExecuteFilter </filter-class> </filter> <! -- Let the core Filter of Struts2 intercept all requests --> <filter-mapping> <filter-name> struts2 </filter-name> <url-pattern>/* </url-pattern> </filter-mapping>

 

In the init () method of StrutsPrepareAndExecuteFilter, the default configuration file struts. xml in the class path is read to complete initialization. Note: struts2 supervises struts. the xml content is stored in the memory in the form of javabean. In the future, struts2 will use the data in the memory for each request processing, instead of reading struts every time. xml file. 2. Configure the struts. xml file.
<struts>      <constant name="struts.devMode" value="true" />      <package name="wbb" namespace="/" extends="struts-default">          <action name="login" class="ruixin.net.wbb.LoginAction" method="execute">              <result name="input">/login.jsp</result>              <result name="success">/page/success.jsp</result>              <result name="error">/error.jsp</result>          </action>      </package>  </struts>  

 

In struts2, the package is used to manage actions. The name attribute is unique and convenient for reference by other packages. The namespace attribute can reduce repeated code. 3. Search Order of Action names 1) obtain the URI of the Request Path. For example, the url is http // localhost: 8080/struts2/path1/path2/path3/test. action 2) First, find the package whose namespace is path1/path2/path3. If the package does not exist, perform Step 3. If the package exists, in this package, find the action named test. When the action cannot be found in this package, the system will directly go to the package of the default namespace to find the action (the default namespace is an empty string ""). If the change action cannot be found in the package of the default namespace, the page prompts that action cannot be found; 3) Find the package whose namespace is/path1/path2. If this package does not exist, go to Step 4 .............. 4) Find the package whose namespace is/path1. If this package does not exist, perform Step 5 ...... 5) Find the package whose namespace is ,.......... 4. default values in Action configuration 1) If no class is specified for action, ActionSupport is used by default. 2) If no method is specified for the action, the execute () method in the action is executed by default. 3) If no result attribute is specified, the default value is success.

Related Article

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.