jar包导入:http://pan.baidu.com/s/1dFBd5Dn
Struts2 开发步骤。
第一步:导入相关struts2的jar包
第二步:在web.xml 添加过滤器来注册struts2
<!-- 配置struts2过滤器 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
第三步:创建Action,继承com.opensymphony.xwork2.ActionSupport。
package com.dx.action;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport{
private static final long serialVersionUID = 1L;
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;
}
public String execute()throws Exception{
return "success";
}
}
第四步:创建struts.xml文件配置action
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="login" class="com.dx.action.LoginAction">
<result name="success">success.jsp</result>
</action>
</package>
</struts>
第五步:启动服务器。