当前位置: 首页 > 知识库问答 >
问题:

尝试在java中加载xml文件时出错500

甄佐
2023-03-14

我有一个大学项目正在进行,我被这个错误困住了,找不到解决方案。首先是加载列表的JSP文件

<%@page import="Controllers.RestClient"%>
<%@page import="java.util.List"%>
<%@page import="Model.Stationss"%>
<%@page import="javax.xml.bind.JAXBException"%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
            <label for="Origin">Embark Station:</label>
            <select name ="StartStation" id="stations">
                <%
                    List<Stationss> listS = RestClient.getStations();
                    for (int i = 0; i < listS.size(); i++) {
                        out.print("<option value = " + i + ">" + listS.get(i).getName() + "</option>");
                    }
                %>
            </select><br>
    </body>
</html>

还有ReST客户端访问权限

package Controllers;

import java.util.List;
import Model.Stationss;
import java.util.ArrayList;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.xml.bind.JAXBException;

public class RestClient {

    public static List<Stationss> getStations() {
        System.out.print("test");
        String link = "http://localhost:8080";
        String path = "/Service/webresources/pkg.service.stations";
        Client client = ClientBuilder.newBuilder().build();
        WebTarget target = client.target(link).path(path);
        Invocation.Builder invocation = target.request(MediaType.APPLICATION_XML);
        System.out.print(link);
        System.out.print(path);
        Response response = invocation.get(Response.class);
        System.out.print(response);
        List<Stationss> list = response.readEntity(new GenericType<List<Stationss>>() {
        });
        System.out.print(list);
        return list;

    }
};

在我拿到模型之后

/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package Model;

import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Stationss {

    private int id;
    private String name;
    private int zone;
    Gate gates = new Gate(zone);

    public int getId() {
        return id;
    }

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

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getZone() {
        return zone;
    }

    public void setZone(int zone) {
        this.zone = zone;
    }

    public Gate getGates() {
        return gates;
    }

    public void setGates(Gate gates) {
        this.gates = gates;
    }

    public Stationss() {
    }

    public Stationss(int id, String name, int zone) {
        this.id = id;
        this.name = name;
        this.zone = zone;
    }

    @Transient
    public CheckTicket enter(String xml) {
        return gates.enter(xml);
    }

    @Transient
    public boolean exit(String xml) {
        return gates.exit(xml);
    }
}

最后,巨大的错误屏幕

HTTP Status 500 – Internal Server Error
Type Exception Report

Message An exception occurred processing [/newjsp.jsp] at line [23]

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.apache.jasper.JasperException: An exception occurred processing [/newjsp.jsp] at line [23]

20:             <label for="Origin">Embark Station:</label>
21:             <select name ="StartStation" id="stations">
22:                 <%
23:                     List<Stationss> listS = RestClient.getStations();
24:                     for (int i = 0; i < listS.size(); i++) {
25:                         out.print("<option value = " + i + ">" + listS.get(i).getName() + "</option>");
26:                     }


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:610)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:499)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:380)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:328)
    jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause

javax.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error
    org.glassfish.jersey.jaxb.internal.AbstractCollectionJaxbProvider.readFrom(AbstractCollectionJaxbProvider.java:359)
    org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.invokeReadFrom(ReaderInterceptorExecutor.java:257)
    org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:236)
    org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:156)
    org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1091)
    org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:874)
    org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:834)
    org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:363)
    org.glassfish.jersey.client.InboundJaxrsResponse$2.call(InboundJaxrsResponse.java:126)
    org.glassfish.jersey.internal.Errors.process(Errors.java:316)
    org.glassfish.jersey.internal.Errors.process(Errors.java:298)
    org.glassfish.jersey.internal.Errors.process(Errors.java:229)
    org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:389)
    org.glassfish.jersey.client.InboundJaxrsResponse.runInScopeIfPossible(InboundJaxrsResponse.java:264)
    org.glassfish.jersey.client.InboundJaxrsResponse.readEntity(InboundJaxrsResponse.java:123)
    Controllers.RestClient.getStations(RestClient.java:36)
    org.apache.jsp.newjsp_jsp._jspService(newjsp_jsp.java:143)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:466)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:380)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:328)
    jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause

javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
 - with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory]
    javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:269)
    javax.xml.bind.ContextFinder.find(ContextFinder.java:412)
    javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:721)
    javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:662)
    org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getStoredJaxbContext(AbstractJaxbProvider.java:288)
    org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getJAXBContext(AbstractJaxbProvider.java:273)
    org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getUnmarshaller(AbstractJaxbProvider.java:189)
    org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getUnmarshaller(AbstractJaxbProvider.java:164)
    org.glassfish.jersey.jaxb.internal.AbstractCollectionJaxbProvider.readFrom(AbstractCollectionJaxbProvider.java:289)
    org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.invokeReadFrom(ReaderInterceptorExecutor.java:257)
    org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:236)
    org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:156)
    org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1091)
    org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:874)
    org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:834)
    org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:363)
    org.glassfish.jersey.client.InboundJaxrsResponse$2.call(InboundJaxrsResponse.java:126)
    org.glassfish.jersey.internal.Errors.process(Errors.java:316)
    org.glassfish.jersey.internal.Errors.process(Errors.java:298)
    org.glassfish.jersey.internal.Errors.process(Errors.java:229)
    org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:389)
    org.glassfish.jersey.client.InboundJaxrsResponse.runInScopeIfPossible(InboundJaxrsResponse.java:264)
    org.glassfish.jersey.client.InboundJaxrsResponse.readEntity(InboundJaxrsResponse.java:123)
    Controllers.RestClient.getStations(RestClient.java:36)
    org.apache.jsp.newjsp_jsp._jspService(newjsp_jsp.java:143)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:466)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:380)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:328)
    jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause

java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory
    org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1444)
    org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1252)
    javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:122)
    javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:155)
    javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:267)
    javax.xml.bind.ContextFinder.find(ContextFinder.java:412)
    javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:721)
    javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:662)
    org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getStoredJaxbContext(AbstractJaxbProvider.java:288)
    org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getJAXBContext(AbstractJaxbProvider.java:273)
    org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getUnmarshaller(AbstractJaxbProvider.java:189)
    org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getUnmarshaller(AbstractJaxbProvider.java:164)
    org.glassfish.jersey.jaxb.internal.AbstractCollectionJaxbProvider.readFrom(AbstractCollectionJaxbProvider.java:289)
    org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.invokeReadFrom(ReaderInterceptorExecutor.java:257)
    org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:236)
    org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:156)
    org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1091)
    org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:874)
    org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:834)
    org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:363)
    org.glassfish.jersey.client.InboundJaxrsResponse$2.call(InboundJaxrsResponse.java:126)
    org.glassfish.jersey.internal.Errors.process(Errors.java:316)
    org.glassfish.jersey.internal.Errors.process(Errors.java:298)
    org.glassfish.jersey.internal.Errors.process(Errors.java:229)
    org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:389)
    org.glassfish.jersey.client.InboundJaxrsResponse.runInScopeIfPossible(InboundJaxrsResponse.java:264)
    org.glassfish.jersey.client.InboundJaxrsResponse.readEntity(InboundJaxrsResponse.java:123)
    Controllers.RestClient.getStations(RestClient.java:36)
    org.apache.jsp.newjsp_jsp._jspService(newjsp_jsp.java:143)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:466)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:380)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:328)
    jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Note The full stack trace of the root cause is available in the server logs.

Apache Tomcat/10.0.16

这是我第一次学习java,我完全不知道自己做错了什么。我知道xml列表的链接工作正常。

共有1个答案

华鹭洋
2023-03-14

您的类路径缺少依赖项

查看堆栈跟踪

javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.

这个答案可能会有帮助

 类似资料:
  • 一段时间以来,我一直在使用Maven和Vaadin 6开发Java应用程序。 我现在需要添加一个附加组件(Vaadin calendar 1.3.0-适用于Vaadin 6)。 我已经在我的pom.xml文件中添加了maven依赖和存储库,正如所附链接上建议的那样,Maven确实下载了我的依赖jar文件,它位于WEB-INF/lib目录中。 但是,当我尝试加载加载页时,我得到以下错误消息(在浏览器

  • 问题内容: 我在.each循环内有以下ajax调用,该调用从服务器加载多个.swf文件: 除IE之外,此功能在所有浏览器上都具有吸引力。有些.swf文件已加载,有些则没有。 我收到的错误如下: 由于错误c00ce514,无法完成操作。 我搜索了这个错误,发现这是由于字符集问题或类似的问题引起的;有些人提供了有关html / xml文件的解决方案,但是我不确定如何为.swf文件修复此问题。有任何想法

  • 第一次在这里问问题,如果这是错误的,我道歉-我会好起来的! 我跟着一个Vue。我试图通过“@import”../node_modules/Bulma/Bulma.sass”文件安装并调用Bulma。 我可以查看我的vue“主页”,但一旦我将“lang=sass”添加到我的样式标记中,我就会不断收到以下错误: "编译失败。 ./节点\模块/css加载器?{“sourceMap”:true}/节点\模

  • 对于minecraft服务器,我尝试使用标准的512MB以上的RAM运行服务器。这曾经对我起作用,但当我最近再次安装服务器时,它停止了工作。我使用以下命令行运行服务器: 但当我运行此脚本时,我得到以下错误: Picked初始化VM时出错,指定的最小和最大堆大小不兼容 操作系统:Windows 7 64bit Java:java7u45(64bit) RAM:8g 如果有人有解决方案,那就太棒了:)

  • 我试图读取xsd文件以验证模式。 我的架构位于位置 我的类读取这个文件也在< code > x/y/z/read schema . Java 中 它们都装在我的罐子里。 我试图在中读取这个文件,如下所示,其中名称是但url返回为null? 我做错什么了吗?

  • 问题内容: 如标题所示,我正在尝试使用for循环将元素添加到xml文档中。我有一个字符串叫,我想遍历,并为每个名称创建一个元素与属性,并与孩子具有的属性,,,和。 不幸的是,如果您在下面的代码中向下滚动到该方法,当我尝试调用时,会出现以下错误: 我看了几个关于stackoverflow的具有相同错误的问题,但是它们似乎都是在与我的情况完全不同的情况下发生的。我最好的猜测是,该错误与以下事实有关:我