Java Web Integration Development (2)--Struts

Source: Internet
Author: User

First, Struts 2.x overview

Do not inherit action from any class

Struts 2 's action does not necessarily implement the action interface or inherit Actionsupport, and any pojo can do the action, as long as the action has the public String execute () method.

Executable method of Action

Execute () is the default method for action. Struts 2 can also perform other methods of action, as long as these methods have no parameters and return a string type. These methods can also have throws declarations, or not. Struts 2 determines, at run time, whether an executable method (parameter, return value) is performed based on the characteristics of the method and is executed through reflection.

Method of executing action via URL

Http://localhost:8080/struts2/loginPerson!logout.action will execute the Loginperson logout () method.

Configure the execution method to action

Struts.xml

 <action name< Span style= "color: #0000ff;" >= "*person"  Class= " Com.helloweenvsfei.struts2.action.LoginAction " method = "{1}" > <result name= "Success" >/welcome.jsp</ result></action>          

Specify the action directory in Web. xml

0 Configuration is the location of the action package that must be specified in the filter for Web. XML, otherwise the action configuration is loaded by default to Struts.xml.

    <Filter>        <Filter-name>Struts</Filter-name>        <Filter-class>Org.apache.struts2.dispatcher.FilterDispatcher</Filter-class>                 <Init-param>            <Param-name>Actionpackages</Param-name>            <Param-value>Com.helloweenvsfei.struts2.action</Param-value>        </Init-param>        <!--    
<init-param> <param-name>struts.action.extension</param-name> <param-value& Gt;helloween</param-value> </init-param> - </Filter>

Summarize:

The Java Web uses threads to process a user's request, and one request corresponds to a processing thread. Struts 2 assigns an action object to each processing thread, injects the submitted parameters into the Action property, and invokes the action's related methods such as execute () to complete the business logic. Therefore, the action of Struts 2 will have multiple objects. After processing, the thread runs and the action is discarded. The action of Struts 2 is thread-safe.

Struts 2 automatically completes the work of taking parameters such as HttpServletRequest, discarding httpservletreques, HttpServletResponse and other servlet APIs, making development and testing easier.

Java Web Integration Development (2)--Struts

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.