日期:2014-05-19  浏览次数:20718 次

新手学习struts2,启动失败,应该是核心拦截器无法加载
本帖最后由 hao7597566 于 2012-12-12 14:46:40 编辑
我在http://struts.apache.org/下载了Apache Struts 2.3.7 Full Distribution,然后将里面lib的85个jar包都放进测试项目的lib目录里面。
同时对web.xml做了如下配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>first Struts 2 Project</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>


另外struts.xml也进行了配置
<?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>
<include file="struts-default.xml"/>
<!--指定web应用的默认编码集,相当于调用HttpServletRequest的setCharacterEncoding的方法 -->
<constant name="struts.i18n.encoding" value="UTF-8"/>
    <constant name="struts.action.extension" value="do" />
    <!-- 开发模式下使用,这样可以打印更详细的错误信息 -->
    <constant name="struts.devMode" value="false" />
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
<package name="express" extends="struts-default">
<!-- 用户登录校验 -->
<action name="checkLogin" class="express.action.LogIn" method="checkLogIn">
<result name="success">/successed.html</result>
<result name="login">/failed.html</result>
</action>
<!-- 默认ACTION -->
<action name="index">
<result>/index.jsp </result>
</action>
</package>

</struts>


另外是写了一个类
package express.action;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import ctrl.Check_Id;

public class LogIn extends ActionSupport {
private String id;
private String pass;
private Check_Id ch=new Check_Id();

public void setId(String id) {
this.id = id;
}

public String getId() {
return this.id;
}

public String checkLogIn() {
if (ch.checke(this.id, this.pass))// 发送密码和ID给业务处理层,并按结果操作
{// 成功就给session赋值,并跳转到成功页面
ActionContext ac = ActionContext.getContext();
ac.getSession().put("ID", this.id);
return SUCCESS;
} else {// 否则跳转到失败页面
return LOGIN;
}
}

}


启动的时候报错(篇幅所限,这里只是最开始的错误)
信息: Starting Servlet Engine: A