第一个页面登录窗口,点击登录按钮后,将用户名和密码显示到第二个页面上。
1.copy struts2 jar包
commons-logging-1.0.4.jar
freemarker-2.3.8.jar
struts2-core-2.0.11.jar
xwork-2.0.4.jar
ognl-2.6.11.jar
2.修改Tomcat server.xml
<Context path="/struts2" docBase="E:\MyEclipse\struts2\WebRoot" reloadable="true" />
3. 修改项目 部署配置文件web.xml
<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
4.新建class处理action
package org.test.struts.action;
public class ActionLogin {
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() throws Exception{
return "success";
}
}
5.新建struts.xml
在WebRoot/WEB-INF/classes文件夹下
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="struts" extends="struts-default">
<action name="login" class="org.test.struts.action.ActionLogin" >
<result name="success" >/result.jsp</result>
</action>
</package>
</struts>
6.建立login.jsp
<form action="login.action" method="post">
username:<input type="text" name="username" /><br>
password:<input type="password" name="password" /><br>
<input type="submit" value="submit" />
</form>
7. 建立result.jsp
username:${request.username }
password:${request.password }