SSH-struts2 entry instances
Struts2 is an implementation of the MVC idea. When studying struts2, it compares it with mvc in. net and finds that they are very similar. Struts2 also has its own controller. Its own understanding is that the Controller in struts2 has an Action method.
When you log on to an instance, the instance transfers the entered content to the Action, and uses the Action to jump to another form.
Login. jsp, used to provide the input box and specify the Action name (login ).
<%@ page language=java contentType=text/html; charset=ISO-8859-1 pageEncoding=ISO-8859-1%>
Set an interceptor in web. xml. Add requests to the filters.
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts2
/*
Struts. xml, which is more like a place where a map is provided. Find the name of the Action Request (login), and then jump to the specified background class; in the configuration file, configure the page to jump to when success is returned.
/result.jsp
LoginAction. jsp provides the execute method. When the page jumps to the background, this method will be searched for further processing. Here we can compare it with the Controller in. net, especially.
package com.syq.struts2;import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport{ private String username; private String password; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String execute(){ return SUCCESS; }}
Result. jsp, if the page to which sucess jumps is returned after the specified execute method is executed.
<%@ page language=java contentType=text/html; charset=ISO-8859-1 pageEncoding=ISO-8859-1%>
username:${requestScope.username}
password:${requestScope.password}
Instance process:
1. the user clicks the form login. jsp to request the resource "login"
2. The Request Path matches the interceptor/* in web. xml /*,
3. It is included in the jurisdiction of the filter org. apache. struts2.dispatcher. ng. filter. StrutsPrepareAndExecuteFilter.
4. Run it in struts. xml to find the "login" name in the action. There may be multiple actions.
5. instantiate the corresponding action class, call various set methods, set the form submitted by the user to the member variable, and then execute the execute method to return the string success
6. The returned string success is compared with the string in the result under action in struts. xml. Find the same string and go to the specified page.
7. Use requestScope to retrieve the corresponding value