1.配置struts2 过滤器
<filter>
<filter-name>Struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>Struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2.配置 struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="hellowPakage" namespace="/" extends="struts-default">
<action name="login" class="com.etop.struts2.action.StrutsAction" >
<result name="success">/suc.jsp</result>
</action>
<action name="resetFom" class="com.etop.struts2.action.StrutsAction" method="resetForm" >
<result name="success" type="redirect">/login.jsp</result>
</action>
</package>
</struts>
3.编写Action
package com.etop.struts2.action;
import com.opensymphony.xwork2.ActionSupport;
/**
* struts2可以是任意一个pojo类 不需要继承任何对象\
* 如果需要使用struts2的高级特性 就必须继承 ActionSupport
* @author teacher
*
*/
public class StrutsAction extends ActionSupport{
private String ruserName;
private String rpassword;
/**
* Struts2方法结构 返回值必须是String类型 不需要任何 参数
* 返回参数 决定需要跳转的jsp
* 必须在struts.xml定义result
* execute是ActionSupport 默认的执行方法
* @return
*/
public String execute(){
return "success";
}
public String resetForm(){
return "success";
}
public String getRuserName() {
return ruserName;
}
public void setRuserName(String ruserName) {
this.ruserName = ruserName;
}
public String getRpassword() {
return rpassword;
}
public void setRpassword(String rpassword) {
this.rpassword = rpassword;
}
}