测试restful时出错

发布于 2024-12-11 01:06:18 字数 5493 浏览 0 评论 0原文

这个项目有什么错误

Error occurred during deployment: Exception while deploying the app [WebApplication] : org.xml.sax.SAXParseException; lineNumber: 30; columnNumber: 30; Deployment descriptor file WEB-INF/web.xml in archive [web].  cvc-complex-type.2.4.a: Invalid content was found starting with element 'persistence-context-ref'. One of '{"http://java.sun.com/xml/ns/j2ee":description, "http://java.sun.com/xml/ns/j2ee":display-name, "http://java.sun.com/xml/ns/j2ee":icon, "http://java.sun.com/xml/ns/j2ee":distributable, "http://java.sun.com/xml/ns/j2ee":context-param, "http://java.sun.com/xml/ns/j2ee":filter, "http://java.sun.com/xml/ns/j2ee":filter-mapping, "http://java.sun.com/xml/ns/j2ee":listener, "http://java.sun.com/xml/ns/j2ee":servlet, "http://java.sun.com/xml/ns/j2ee":servlet-mapping, "http://java.sun.com/xml/ns/j2ee":session-config, "http://java.sun.com/xml/ns/j2ee":mime-mapping, "http://java.sun.com/xml/ns/j2ee":welcome-file-list, "http://java.sun.com/xml/ns/j2ee":error-page, "http://java.sun.com/xml/ns/j2ee":jsp-config, "http://java.sun.com/xml/ns/j2ee":security-constraint, "http://java.sun.com/xml/ns/j2ee":login-config, "http://java.sun.com/xml/ns/j2ee":security-role, "http://java.sun.com/xml/ns/j2ee":env-entry, "http://java.sun.com/xml/ns/j2ee":ejb-ref, "http://java.sun.com/xml/ns/j2ee":ejb-local-ref, "http://java.sun.com/xml/ns/j2ee":service-ref, "http://java.sun.com/xml/ns/j2ee":resource-ref, "http://java.sun.com/xml/ns/j2ee":resource-env-ref, "http://java.sun.com/xml/ns/j2ee":message-destination-ref, "http://java.sun.com/xml/ns/j2ee":message-destination, "http://java.sun.com/xml/ns/j2ee":locale-encoding-mapping-list}' is expected.. Please see server.log for more details.
    C:\Users\win-7\Desktop\WebApplication\nbproject\build-impl.xml:727: 
    The module has not been deployed.
        at org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(Deployment.java:210)
        at org.netbeans.modules.j2ee.ant.Deploy.execute(Deploy.java:106)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
        at sun.reflect.GeneratedMethodAccessor79.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:390)
        at org.apache.tools.ant.Target.performTasks(Target.java:411)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
        at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:284)
        at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:539)
        at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:153)
    BUILD FAILED (total time: 2 seconds)

我正在使用 netbeans 7.0.1 web.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<web-app
 xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
     <servlet>
         <description>Generated servlet for Java ME Client to Web Application </description>
         <display-name>Javon service for  MyPackage.WebToMobileServlet</display-name>
         <servlet-name>WebToMobileServlet</servlet-name>
         <servlet-class>MyPackage.WebToMobileServlet</servlet-class>
     </servlet>
     <servlet>
         <servlet-name>ServletAdaptor</servlet-name>
         <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
         <load-on-startup>1</load-on-startup>
     </servlet>
     <servlet-mapping>
         <servlet-name>WebToMobileServlet</servlet-name>
        <url-pattern>/servlet/MyPackage.WebToMobileServlet</url-pattern>
     </servlet-mapping>
     <servlet-mapping>
         <servlet-name>ServletAdaptor</servlet-name>
         <url-pattern>/resources/*</url-pattern>
     </servlet-mapping>
     <session-config>
         <session-timeout>
             30
         </session-timeout>
     </session-config>
     <welcome-file-list>
         <welcome-file>index.jsp</welcome-file>
     </welcome-file-list> 
     <persistence-context-ref> 
        <persistence-context-ref-name>persistence/WebApplicationPU</persistence-context-ref-name>
        <persistence-unit-name>WebApplicationPU</persistence-unit-name>
     </persistence-context-ref> 
     <resource-ref>
         <res-ref-name>UserTransaction</res-ref-name>
         <res-type>javax.transaction.UserTransaction</res-type>
         <res-auth>Container</res-auth> 
     </resource-ref> 
</web-app>

what is the error at this project i am using netbeans 7.0.1

Error occurred during deployment: Exception while deploying the app [WebApplication] : org.xml.sax.SAXParseException; lineNumber: 30; columnNumber: 30; Deployment descriptor file WEB-INF/web.xml in archive [web].  cvc-complex-type.2.4.a: Invalid content was found starting with element 'persistence-context-ref'. One of '{"http://java.sun.com/xml/ns/j2ee":description, "http://java.sun.com/xml/ns/j2ee":display-name, "http://java.sun.com/xml/ns/j2ee":icon, "http://java.sun.com/xml/ns/j2ee":distributable, "http://java.sun.com/xml/ns/j2ee":context-param, "http://java.sun.com/xml/ns/j2ee":filter, "http://java.sun.com/xml/ns/j2ee":filter-mapping, "http://java.sun.com/xml/ns/j2ee":listener, "http://java.sun.com/xml/ns/j2ee":servlet, "http://java.sun.com/xml/ns/j2ee":servlet-mapping, "http://java.sun.com/xml/ns/j2ee":session-config, "http://java.sun.com/xml/ns/j2ee":mime-mapping, "http://java.sun.com/xml/ns/j2ee":welcome-file-list, "http://java.sun.com/xml/ns/j2ee":error-page, "http://java.sun.com/xml/ns/j2ee":jsp-config, "http://java.sun.com/xml/ns/j2ee":security-constraint, "http://java.sun.com/xml/ns/j2ee":login-config, "http://java.sun.com/xml/ns/j2ee":security-role, "http://java.sun.com/xml/ns/j2ee":env-entry, "http://java.sun.com/xml/ns/j2ee":ejb-ref, "http://java.sun.com/xml/ns/j2ee":ejb-local-ref, "http://java.sun.com/xml/ns/j2ee":service-ref, "http://java.sun.com/xml/ns/j2ee":resource-ref, "http://java.sun.com/xml/ns/j2ee":resource-env-ref, "http://java.sun.com/xml/ns/j2ee":message-destination-ref, "http://java.sun.com/xml/ns/j2ee":message-destination, "http://java.sun.com/xml/ns/j2ee":locale-encoding-mapping-list}' is expected.. Please see server.log for more details.
    C:\Users\win-7\Desktop\WebApplication\nbproject\build-impl.xml:727: 
    The module has not been deployed.
        at org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(Deployment.java:210)
        at org.netbeans.modules.j2ee.ant.Deploy.execute(Deploy.java:106)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
        at sun.reflect.GeneratedMethodAccessor79.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:390)
        at org.apache.tools.ant.Target.performTasks(Target.java:411)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
        at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:284)
        at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:539)
        at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:153)
    BUILD FAILED (total time: 2 seconds)

web.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<web-app
 xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
     <servlet>
         <description>Generated servlet for Java ME Client to Web Application </description>
         <display-name>Javon service for  MyPackage.WebToMobileServlet</display-name>
         <servlet-name>WebToMobileServlet</servlet-name>
         <servlet-class>MyPackage.WebToMobileServlet</servlet-class>
     </servlet>
     <servlet>
         <servlet-name>ServletAdaptor</servlet-name>
         <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
         <load-on-startup>1</load-on-startup>
     </servlet>
     <servlet-mapping>
         <servlet-name>WebToMobileServlet</servlet-name>
        <url-pattern>/servlet/MyPackage.WebToMobileServlet</url-pattern>
     </servlet-mapping>
     <servlet-mapping>
         <servlet-name>ServletAdaptor</servlet-name>
         <url-pattern>/resources/*</url-pattern>
     </servlet-mapping>
     <session-config>
         <session-timeout>
             30
         </session-timeout>
     </session-config>
     <welcome-file-list>
         <welcome-file>index.jsp</welcome-file>
     </welcome-file-list> 
     <persistence-context-ref> 
        <persistence-context-ref-name>persistence/WebApplicationPU</persistence-context-ref-name>
        <persistence-unit-name>WebApplicationPU</persistence-unit-name>
     </persistence-context-ref> 
     <resource-ref>
         <res-ref-name>UserTransaction</res-ref-name>
         <res-type>javax.transaction.UserTransaction</res-type>
         <res-auth>Container</res-auth> 
     </resource-ref> 
</web-app>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我一直都在从未离去 2024-12-18 01:06:19

您的 web.xml 文件格式错误,您可以将其发布到此处吗?

elemnet persistence-context-ref 属于 Java EE 5。您的 web.xml 应该使用 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd 架构不是 http://java.sun.com/xml/ns/j2ee/web-app_2_4 .xsd

仅更改此内容无法解决问题,您的项目是为 1.4 规范创建的,而该标签是针对 Java EE 5 规范的。

使用正确的规范版本重新创建项目,或者不使用该标签。

web.xml 文件的标头必须如下所示:

xmlns="http://java.sun.com/xml/ns/javaee"  
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5"  
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

Your web.xml file is malformed, can you post it here?

The elemnet persistence-context-ref belongs to Java EE 5. Your web.xml should be using http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd schema not http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd

Changing only this will not fix the problem, your project was created for 1.4 spec and that tag is for Java EE 5 spec.

Recreate the project with the correct spec version or don't use that tag.

The header of the web.xml file must look like this:

xmlns="http://java.sun.com/xml/ns/javaee"  
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5"  
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
自由范儿 2024-12-18 01:06:19

您的 web.xml 似乎格式错误或无序。您可以将其发布在这里,也许我们可以解决这个问题吗?

web.xml 位于名为 WEB-INF 的目录中

It looks like your web.xml is malformed or out of order. Can you post it here and maybe we can eyeball the problem?

The web.xml is located in a directory called WEB-INF

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文