初次整合struts2和string,在用ant部署时遇到下面的问题
services-undeploy-absolute:
 [undeploy] OK - Undeployed application at context path /ch23
   [deploy] FAIL - Deployed application at context path /ch23 but context failed to startBUILD FAILED
E:\Workspace\ch23\build.xml:39: FAIL - Deployed application at context path /ch23 but context failed to start
网上查了一些资料,觉得是web.xml的问题
web.xml代码<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 
 xmlns="http://java.sun.com/xml/ns/j2ee" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
   <display-name>Welcome to Tomcat</display-name>
  <description>
     Java Web开发入门与精通
  </description>
       <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>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <jsp-config>
    <taglib> 
        <taglib-uri>/spring</taglib-uri> 
        <taglib-location>/WEB-INF/spring.tld</taglib-location> 
</taglib>
    <taglib>     
        <taglib-uri>/struts-tags</taglib-uri>
        <taglib-location>/WEB-INF/struts-tags.tld</taglib-location>
    </taglib>
    </jsp-config>
   

</web-app>然后我把<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>
去掉,ant部署成功,但是这个时候主页的login.jsp打不开
报错如下
description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: An exception occurred processing JSP page /login.jsp at line 74: <head><title>鐧婚檰</title></head> 
5: <body> 
6: <table>
7:    <s:form id="id" action="login">
8:     <s:textfield name="username" key="username"/>
9:     <s:password name="password1" key="password1"/>
10:     <s:submit key="submit"/>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:553)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:457)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause The Struts dispatcher cannot be found.  This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]
org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:60)
org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:44)
org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:48)
org.apache.jsp.login_jsp._jspx_meth_s_005fform_005f0(login_jsp.java:114)
org.apache.jsp.login_jsp._jspService(login_jsp.java:84)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.16 logs.
--------------------------------------------------------------------------------Apache Tomcat/7.0.16
根据This is usually caused by using Struts tags without the associated filter.
看意思好像是少了filter,但是加上上面的filter以后ant又报错,甚是不解
login.jsp源代码如下<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html> 
<head><title>登陆</title></head> 
<body> 
<table>
   <s:form id="id" action="login">
    <s:textfield name="username" key="username"/>
    <s:password name="password1" key="password1"/>
    <s:submit key="submit"/>
</s:form>
</table>
</body> 
</html>
希望各位能抽出宝贵的时间帮小弟看看错误出在哪了

解决方案 »

  1.   

    看下struts在web.xml里的配置吧。我手机看不出来……
      

  2.   

    你的struts是2.0.14的还是2.2.X的,好像后者的filter是这样子的。
    <filter>
            <filter-name>struts2</filter-name>
            <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
        </filter>
      

  3.   

    谢谢各位的回答,我不用ant部署,换成Eclipse的部署后,没什么问题了,估计是ant模板的问题吧,ant刚开始用,看书上讲大部分人都用ant进行部署,所以想练习一下,结果老出些莫名其妙的问题,解决不了,目前还没发现ant部署有什么好的,直接用Eclipse的部署就很方便嘛,不知道各位都用什么进行部署,呵呵,祝各位一切顺心