In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail the example analysis on the use of struts2 process. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
1. The client initiates a request to the servlet container (Tomcat)
two。 The request goes through a series of filters, and then FilterDispatcher is called
3.FilterDispatcher asks ActionMapper to decide whether this request calls an action.
4. If ActionMapper decides to call an Action,FilterDispatcher to give the processing of the request to ActionProxy,ActionPro according to the configuration file of the ConfigurationManager query framework, find the Action class that needs to be called, usually read the struts.xml
5.ActionProxy creates an instance of ActionInvocation, and the ActionInvocation instance is called using a naming schema. Before and after the process of calling Action, it involves the call of the relevant interceptor.
6. Once the Action is executed, ActionInvocation finds the corresponding return result according to the configuration in struts.xml.
Such as the code:
After struts2 has obtained the .action request, it will decide which business logic component to invoke based on the part.
Action in struts2 applications is defined in struts.xml.
The Action instance that struts2 uses to process user requests is not a user-implemented business controller, but an Action proxy, because the user-implemented business controller is not coupled to ServletAPI and obviously cannot handle user requests.
SUCCESS USERNAME: PASSWORD:
For example, the hello.action of the above form, this action attribute is not an ordinary servlet, nor is it a dynamic JSP page. When the form is submitted to hello.action, the FilterDispatcher of Struts2 will work and forward the user's request to the corresponding Action.
Note that Struts2 Action intercepts all requests with the suffix .action by default, and if we need to submit the form to Action for processing, we should set the form action property to the .action format.
Controller class
Public class HelloAction {private String name; private String pass; public void setName (String name) {this.name=name;} public void setPass (String pass) {this.pass=pass } public String execute () {if ("yang" .equals (name) & & "1234" .equals (pass)) {return "success";} else {return "error";}
After the previous execution is completed, only the forwarding of the page is performed, and the status of the user is not tracked. When the user logs in, we need to add the user name as the status information of HTTPSession.
To access the Httpsession instance, struts2 provides an ActionContext class that provides a getSession () get method, but the return value of this method is not HttpSession () but Map (), but the interceptor of Struts2 is responsible for switching between the Session () and HttpSession ().
To check whether the session property we set is successful, you can set it to the interface after success.
SUCCESS Welcome, ${sessionScope.user}, you are logged in.
Use JSP2.0 expression syntax to output the user attribute in HTTP Session.
Action tool class integrates ActionSupport
The ActionSupport class is a utility class, and it has implemented the Action interface. In addition, it also implements the Validateablez interface and provides the data verification function.
In order to increase the check function of input data, the override validate method is added in Action.
Public void validate () {if (getName () = = null | | getName (). Trim (). Equals (")) {addFieldError (" name ", getText (" name.required "));} if (getPass () = = null | | getPass (). Trim (). Equals (")) {addFieldError ("pass", getText ("pass.required"));}}
The overridden validate method added above is executed before the system's execute () method. If the fieldError of the Action class already contains a data verification error after the method is executed, the request will be forwarded to the input logical view, so add the input logical view name to the struts.xml and let it jump to the login page.
The disadvantage of this validate method is that it requires a lot of rewriting of the validate method, so you can use struts2's validation framework for verification.
This is the end of this article on "sample analysis of using struts2 processes". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.