日期:2014-05-17  浏览次数:20621 次

帮忙看下这个web.xml配置。。
Java code


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

    <filter>
        <filter-name>Set Character Encoding</filter-name>
        <filter-class>SetCharacterEncodingFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>Set Character Encoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
 

 
    <servlet>
        <servlet-name>action</servlet-name>
        <servlet-class>
            org.apache.struts.action.ActionServlet
        </servlet-class>
        <init-param>
            <param-name>config</param-name>
            <param-value>/WEB-INF/struts-config.xml</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>


    <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>locale</servlet-name>
        <servlet-class>LocaleServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>locale</servlet-name>
        <url-pattern>locale</url-pattern>
    </servlet-mapping>
 
    <!-- The Usual Welcome File List -->
    <welcome-file-list>
        <welcome-file>hello.jsp</welcome-file>
    </welcome-file-list>

    <!-- Struts Tag Library Descriptors -->
    <taglib>
        <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
        <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
    </taglib>

    <taglib>
        <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
        <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
    </taglib>

    <taglib>
        <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
        <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
    </taglib>

</web-app>




说是与web.xml的dtd不匹配。。这里面有两对<servlet></servlet>我删除其中任意一对就不报错了。。但这样行不通啊。<servlet></servlet>不是允许多对的么?

------解决方案--------------------
如果不行的话把两个<servlet></servlet>都加上这句话 我这边是这样的 个中缘由不是很清楚
------解决方案--------------------
先写

<servlet>
</servlet>

后写
<servlet-mapping>
</servlet-mapping>

如果有几个servlet 必须是<servlet>
</servlet>写在一起,<servlet-mapping>
</servlet-mapping>写在一起。

比如:

<servlet></servlet>
<servlet></servlet>

<servlet-mapping>
</servlet-mapping>
<servlet-mapping>
</servlet-mapping>

懂了吧。


----
 <servlet>
<servlet-name>action</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>

<servlet>
<servlet-name>locale<