小编典典

在没有Maven的Tomcat中使用泽西文件上传服务

tomcat

我想使用 平稳的 jersey Web服务将图像上传到服务器。我包括了 jersey-multipart-1.9.jar
jersey-bundle-1.14.jarasm-3.3.1.jar jar文件, 但我没有使用Maven
下面的代码段用于上传功能。

@POST
@Path("/uploadImage")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(@FormDataParam("file") InputStream fileInputStream,
                           @FormDataParam("file") FormDataContentDisposition contentDispositionHeader) { String filePath = SERVER_UPLOAD_LOCATION_FOLDER    + contentDispositionHeader.getFileName();
    saveFile(fileInputStream, filePath);//method to save the file.
    String output = "File saved to server location : " + filePath;
    return Response.status(200).entity(output).build();

}

但是当我在Tomcat 7中部署或运行​​它时出现以下错误。

SEVERE: Missing dependency for method public javax.ws.rs.core.Response com.sec.samsung.FileUpload.uploadFile(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition) at parameter at index 0
SEVERE: Missing dependency for method public javax.ws.rs.core.Response com.sec.samsung.FileUpload.uploadFile(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition) at parameter at index 1
SEVERE: Method, public javax.ws.rs.core.Response com.sec.samsung.FileUpload.uploadFile(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition), annotated with POST of resource, class com.sec.samsung.FileUpload, is not recognized as valid resource method.
SEVERE: Servlet /uploadImage threw load() exception
com.sun.jersey.spi.inject.Errors$ErrorMessagesException
at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:765)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:760)
at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:489)
at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:319)
at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609)
at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:374)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:557)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1197)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5210)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5493)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

没有maven支持,谁能帮助我?很多人都问过同样的问题,但是可以使用Maven解决方案,但是我不在Maven项目上工作。


阅读 299

收藏
2020-06-16

共1个答案

小编典典

我尝试了类似的代码

    //code
@POST
@Path("/uploadImage")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(@FormDataParam("file") InputStream uploadedStream,
        @FormDataParam("file") FormDataContentDisposition fileDetail) {
    String fileName = fileDetail.getFileName();
    saveToFile(uploadedStream,fileName);
    String output = "File saved to server location : " + fileName;
    return Response.status(200).entity(output).build();
}

在(Tomcat 7)中使用波纹管jar文件并正常工作

   jersey-multipart-1.18.1.jar
   mimepull-1.9.3.jar
   jersey-core-1.18.1.jar
   jersey-servlet-1.18.1.jar
   jersey-server-1.18.1.jar
2020-06-16