简体   繁体   English

500-servlet球衣剩余服务的servlet.init()抛出异常

[英]500 - servlet.init() for servlet jersey rest service threw exception

I have included jar files jersey-archive-1.18 , jersey-multipart.jar and mimepull.jar This is my class file (UploadFileService.java) inside the package com.mkyong.rest 我已经将jar文件jersey-archive-1.18,jersey-multipart.jar和mimepull.jar包括在内。这是我的类文件(UploadFileService.java),位于包com.mkyong.rest中。

 package com.mkyong.rest;

    import javax.ws.rs.Path;
    //import javax.ws.rs.Produces;
    import javax.ws.rs.core.MediaType;

    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;

    import javax.ws.rs.Consumes;


    import javax.ws.rs.POST;
    import javax.ws.rs.core.Response;
    import com.sun.jersey.core.header.FormDataContentDisposition;
    import com.sun.jersey.multipart.FormDataParam;


    @Path("/file")
    public class UploadFileService {

    @POST
    @Path("/upload")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public Response uploadFile( @FormDataParam("file") InputStream uploadedInputStream,
        @FormDataParam("file") FormDataContentDisposition fileDetail) {

        System.out.println("ok");
       /* String uploadedFileLocation = "d://upload/" + fileDetail.getFileName();*/
        String uploadedFileLocation = "d://upload/" + "abc.pdf";

            writeToFile(uploadedInputStream, uploadedFileLocation);

            String output = "File uploaded to : " + uploadedFileLocation;

            return Response.status(200).entity(output).build();

            }

    private void writeToFile(InputStream uploadedInputStream,
                                    String uploadedFileLocation) {
        try {
                OutputStream out = new FileOutputStream(new File(
                uploadedFileLocation));
                int read = 0;
                byte[] bytes = new byte[1024];

                out = new FileOutputStream(new File(uploadedFileLocation));
                while ((read = uploadedInputStream.read(bytes)) != -1) 
                {
                  out.write(bytes, 0, read);
                }
                out.flush();
                out.close();
            } catch (IOException e) {

               e.printStackTrace();
            }
    }

    }

This Upload.html 此Upload.html

<form action="rest/file/upload" method="post" enctype="multipart/form-data" style="margin-top:20px;margin-bottom:30px;width:100%;height:60px;">

    <input type="file" name="file"  class="btn btn-info btn-xm" style="float:left;margin-right:6px;margin-bottom:10px;"/>
    <p>Target Upload Path : <input type="text" name="path" /></p>
    <input type="submit" class="btn btn-warning" value="Upload" style="float:left;" id="Map" value="Map" onclick="showImg()"/>

    <img src="image/loading.gif" id="map_img" style="display: none;"/>
    <span id="countdown" class="btn btn-danger" style="float:right;"></span>

 </form>

And this is the servlet mapping in web.xml config 这是web.xml配置中的servlet映射

<display-name>RESTfulWS</display-name>   
<servlet> 
<servlet-name>Jersey REST Service</servlet-name> 
<servlet-class>com.sun.jersey.spi.container.servlet.UploadFileService</servlet-class> 
<init-param> 
<param-name>com.sun.jersey.config.property.packages</param-name> 
<param-value>com.mkyong.rest</param-value> 
</init-param> 

<load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
<servlet-name>Jersey REST Service</servlet-name> 
<url-pattern>/rest/*</url-pattern> 
</servlet-mapping>

Can you please tell me where I am wrong, I am getting the following error: 能否请您告诉我哪里错了,出现以下错误:

javax.servlet.ServletException: Servlet.init() for servlet Jersey REST Service threw exception
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:76)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:934)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:515)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1012)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:642)
    org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1597)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1555)
    java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    java.lang.Thread.run(Unknown Source)
root cause

com.sun.jersey.spi.inject.Errors$ErrorMessagesException
    com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
    com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
    com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
    com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795)
    com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:790)
    com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:491)
    com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:321)
    com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605)
    com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207)
    com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:376)
    com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:559)
    javax.servlet.GenericServlet.init(GenericServlet.java:160)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:76)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:934)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:515)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1012)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:642)
    org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1597)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1555)
    java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    java.lang.Thread.run(Unknown Source)

Add the following code to your.project file in the appropriate location. 将以下代码添加到your.project文件中的适当位置。

<buildCommand>
        <name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
        <arguments>
        </arguments>
</buildCommand>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 HTTP 状态 500 - servlet Jersey Web 应用程序的 Servlet.init() 抛出异常 REST Web 服务错误 - HTTP Status 500 - Servlet.init() for servlet Jersey Web Application threw exception REST web-service error servlet ctakes-rest-service 的 Servlet.init() 抛出异常 - Servlet.init() for servlet ctakes-rest-service threw exception HTTP状态500-Servlet球衣的Servlet.init()-Servlet抛出异常 - HTTP Status 500 - Servlet.init() for servlet jersey -servlet threw exception HTTP状态500-Servlet球衣-serlvet的Servlet.init()抛出异常? - HTTP Status 500 - Servlet.init() for servlet jersey-serlvet threw exception? 如何修复 HTTP 状态 500 - Servlet.init() for servlet jersey 抛出异常? - How can I fix HTTP Status 500 - Servlet.init() for servlet jersey threw exception? HTTP 状态 500 - servlet 的 Servlet.init() Jersey Web 应用程序抛出异常 - HTTP Status 500 - Servlet.init() for servlet Jersey Web Application threw exception HTTP 状态 500 - servlet appServlet 的 Servlet.init() 抛出异常 - HTTP Status 500 - Servlet.init() for servlet appServlet threw exception HTTP状态500-Servlet Dispatcher的Servlet.init()抛出异常 - HTTP Status 500 - Servlet.init() for servlet Dispatcher threw exception HTTP状态500-Servlet HelloWeb的Servlet.init()抛出异常? - HTTP Status 500 - Servlet.init() for servlet HelloWeb threw exception? HTTP状态500 - servlet fitTrackerServlet的Servlet.init()引发异常 - HTTP Status 500 - Servlet.init() for servlet fitTrackerServlet threw exception
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM