In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the example analysis of struts2, which has certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let Xiaobian take you to understand it together.
Struts2 controller is a filter, Struts Action is equivalent to a basic MVC design pattern in which an independent servlet, and by the Action call model layer (JavaBean) to complete a specific business function.
Create an example in struts2
Create a new WEB project, then right-click Myeclipse->addstrutsCapabilities on the project, select struts2 in the interface, then click finish, and you will see struts.xml under src file.
Then it's up to configure filters in the web.xml file, configure struts.xml file, and write action classes.
Struts2's action class doesn't require any interfaces, just a POJO class that contains execute methods. When the necessary interceptors are executed, the program executes the execute method.
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 Struts2, the Struts.xml configuration file created by right-clicking src will be automatically published to the WEB-INFI/classes directory. This is the file that Struts loads by default and is used to configure the actions that Struts2 needs to call.
/success.jsp /error.jsp
Finally, request http://localhost:10086/ZstrutsDemo/hello.action? in your browser. name=yang&pass=1234
That is, you can see that the page jumps to the corresponding interface
Thank you for reading this article carefully. I hope that the article "Struts2 Sample Analysis" shared by Xiaobian will be helpful to everyone. At the same time, I hope that everyone will support you a lot and pay attention to the industry information channel. More relevant knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.