java 将 web.xml 从 2.3 升级到 2.4 时出现问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4156919/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 05:05:49  来源:igfitidea点击:

Problem while Upgrading web.xml to 2.4 from 2.3

javaservletsweblogic

提问by nasaa

I am trying to upgrade my web.xml from 2.3 to 2.4, so I changed my web.xml to something like this -

我正在尝试将我的 web.xml 从 2.3 升级到 2.4,所以我将我的 web.xml 更改为这样的 -

<?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">
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 8.1
Servlet 2.4//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_2_4-1.dtd">-->

<!--
    ===========================================================
                           WUI - WEB.XML
    ===========================================================
--> 

<web-app id="WebApp" 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"
    version="2.4">

    <description>Odyssey Web User Interface</description>
    <display-name>wui</display-name>



<!-- Uncomment this when setting up the prevent-multiple-login mechanism -->
<!--
    <listener>
        <listener-class>com.xxx.xxxnListener</listener-class>
    </listener>
-->

    <!--  local cache filter setup -->
    <filter> 
      <filter-name>local-cache</filter-name> 
      <filter-class>com.xxx.xxxcheFilter</filter-class> 
   </filter> 
....

When I start my Server, I get this error -

当我启动服务器时,出现此错误 -

weblogic.descriptor.DescriptorException: VALIDATION PROBLEMS WERE FOUND problem: cvc-complex-type.2.4a: Expected elements 'servlet-class@http://java.sun.com/xml/ns/javaee jsp-file@http://java.sun.com/xml/ns/javaee' instead of 'display-name@http://java.sun.com/xml/ns/javaee' here in element servlet@http://java.sun.com/xml/ns/javaee: problem: cvc-complex-type.2.4a: Expected elements 'servlet-class@http://java.sun.com/xml/ns/javaee jsp-file@http://java.sun.com/xml/ns/javaee' instead of 'description@http://java.sun.com/xml/ns/javaee' here in element servlet@http://java.sun.com/xml/ns/javaee:

weblogic.descriptor.DescriptorException:发现验证问题问题:cvc-complex-type.2.4a:预期元素'servlet-class@http://java.sun.com/xml/ns/javaee jsp-file@http:// /java.sun.com/xml/ns/javaee' 而不是 'display-name@http://java.sun.com/xml/ns/javaee' 在元素 servlet@http://java.sun.com 中/xml/ns/javaee:问题:cvc-complex-type.2.4a:预期元素'servlet-class@http://java.sun.com/xml/ns/javaee jsp-file@http://java. sun.com/xml/ns/javaee' 而不是 'description@http://java.sun.com/xml/ns/javaee' 在元素 servlet@http://java.sun.com/xml/ns/ 中爪哇:

I am using weblogic 10.1 server.

我正在使用 weblogic 10.1 服务器。

Any idea what else am I supposed to do.

知道我还应该做什么。

Thanks.

谢谢。

回答by Martijn Verburg

The structure of your web.xmlneeds to change to pass the new XSD. For example the new XSD states that your web.xml file should have:

web.xml需要更改结构以通过新的 XSD。例如,新的 XSD 声明您的 web.xml 文件应该具有:

<servlet-class>or <jsp-file>as an element in the place where you currently have <display-name>

<servlet-class><jsp-file>作为您当前拥有的地方的元素 <display-name>

Read the XSD at http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsdfor more details, it shouldn't take long to restructure so that it passes.

阅读http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd 上的 XSD 以了解更多详细信息,重构它应该不需要很长时间,以便它通过。

回答by axtavt

XML Schema definition for Servlet 2.4 uses <xsd:sequence>to describe contents of <servlet>element, therefore is enforces a specific order of these elements. For example, <servlet-name>must be the first child of <servlet>.

Servlet 2.4 的 XML 模式定义用于<xsd:sequence>描述<servlet>元素的内容,因此强制执行这些元素的特定顺序。例如,<servlet-name>必须是 的第一个孩子<servlet>

回答by Shakthifuture

Use the below code for change 2.3 to 2.5

使用以下代码将 2.3 更改为 2.5

<web-app 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">