Struts2 (1) --- struts2 environment establishment and instance
I have just been familiar with struts2, but I am a little confused. I am still used to writing code first, and then gradually understand the ideas.
This article mainly describes how to use struts to simplify programming by setting up the strusts environment and using a simple example.
1. The project structure is as follows, including required packages.
2. web. xml
Struts2
Org. apache. struts2.dispatcher. ng. filter. StrutsPrepareAndExecuteFilter
Struts2
/*
Index. jsp
3. struts. xml
/Welcome. jsp
/Login.html
/Login.html
4. LoginAction. java
Package action; import com. opensymphony. xwork2.ActionSupport; // This class inherits the ActionSupport class. In this way, you can directly use variables such as SUCCESS and LOGIN and the public class LoginAction extends ActionSupport {private String name; private String password; public String getName () {return name ;} public void setName (String name) {this. name = name;} public String getPassword () {return password;} public void setPassword (String password) {this. password = password;}/*** return value here use the custom * @ return */public String index () {return index ;} /*** the return value directly uses variables such as SUCCESS */public String execute () {// The value if (sa. equals (name) & aaaaaa. equals (password) return SUCCESS; return LOGIN ;}}
6.login.html
7.welcome.html
<%@ page language=java import=java.util.* pageEncoding=ISO-8859-1%><%String path = request.getContextPath();String basePath = request.getScheme()+://+request.getServerName()+:+request.getServerPort()+path+/;%>
>
welcome!!!
After tomcat is started, enter http: // localhost: 8080/struts2/index in the address bar to open login.html.
Enter sa and aaaaaa to open welcome. jsp.