English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Struts2the controller is a filter, and the Action in Struts is equivalent to a separate servlet in the basic MVC design pattern, and each Action calls the model layer (JavaBean) to complete specific business functions.
In struts2to create an example
Create a new WEB project, then right-click on the project and select Myeclipse–>addstrutsCapabilities. In the interface, select struts2After that, click finish. After completion, you will see the Struts configuration file struts.xml under the src file.
Then it is to configure the filter in the web.xml file, configure the struts.xml file, and write the action class.
Struts2The action class does not need any interfaces, just a regular class (POJO) that contains the execute method. After executing the necessary interceptors, the program will execute the execute method, action class:
public class HelloAction{ private String name; private String password; public void setName(String name){ this.name=name; } public void setPassword(String password){ this.password=password; } public String execute() throws Exception{ if("yang".equals(name) && "123456".equals(password)){ return "success"; } else{ return "error"; } } }
When configuring Struts2when, the Struts.xml configuration file created by right-clicking on src will be automatically deployed to WEB-INFI/Under the 'classes' directory, this is a file that Struts will load by default, used for configuring Struts2action.
default">--action to be called.-Configure package, must inherit Struts--Configure by action, the name hello is the URL accessed: hello.action default <struts>2<package name="struts-" extends="struts default">--<!--Configure by action, the name hello is the URL accessed: hello.action > <action name="hello" class="org.yangjq.HelloAction">/<result name="success">/result> <result name="error">/error.jsp</result> </action> </package> </struts>
Finally, make a request in the browser to http://localhost:10086/ZstrutsDemo/hello.action#63;name=yang&pass=1234
You can see the page jump to the corresponding interface
Summary
That is all about struts in this article2Introduction and all the content of code examples, hoping it will be helpful to everyone. Those who are interested can continue to refer to this site:
struts2Development Process and Detailed Configuration
Struts2Introduction to String Trimming Code
Struts2 Detailed Explanation of OGNL Expression Examples
If there are any shortcomings, please leave a message to point them out. Thank you friends for your support of this site!
Statement: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (Please replace # with @ when sending an email to report, and provide relevant evidence. Once verified, this site will immediately delete the infringing content.)