Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法使用rest服务上载文件_Java_Web Services_Rest_File Upload - Fatal编程技术网

Java 无法使用rest服务上载文件

Java 无法使用rest服务上载文件,java,web-services,rest,file-upload,Java,Web Services,Rest,File Upload,我使用restwebserivce做了一个上传文件的示例应用程序。 这不是Maven项目,只是示例项目。 下面是web.xml文件 <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

我使用restwebserivce做了一个上传文件的示例应用程序。 这不是Maven项目,只是示例项目。 下面是web.xml文件

  <?xml version="1.0" encoding="UTF-8"?>
   <web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
    <display-name>JAX RS Application</display-name>

<servlet>
    <servlet-name>REST Service</servlet-name>
    <servlet-class>
        com.sun.jersey.spi.container.servlet.ServletContainer
    </servlet-class>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>com.eb.rajesign.util</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>REST Service</servlet-name>
    <url-pattern>/resource/*</url-pattern>
</servlet-mapping>
我还添加了jar文件列表:

jersey-bundle-1.6.jar jersey-core-1.18.jar jersey-multipart-1.18.1.jar jersey-server-1.18.1.jar jersey-servlet-1.18.1.jar mimepull-1.9.3.jar jersey-bundle-1.14.jar asm-3.3.1.jar

我无法上传文件。你能建议我吗? 获取错误: [11/18/15 22:18:40:147 IST]00000215 ServletWrappe com.ibm.ws.webcontainer.servlet.ServletWrapper init Uncaught.init.exception.shown.by.servlet [11/18/15 22:18:40:147 IST]00000215 webapp E com.ibm.ws.webcontainer.webapp.webapp logServletError SRVE0293E:[Servlet错误]-[REST服务]:java.lang.IllegalAccessError:Class com/sun/jersey/spi/scanning/annotationscannerlister非法访问com/sun/jersey/core/reflection/ReflectionHelper类的“私有”成员 在com.sun.jersey.spi.scanning.AnnotationScannerListener.(AnnotationScannerListener.java:92)

<body>
 <form action="resource/restwb/upload" method="post"    enctype="multipart/form-data">
     File : <input type="file" name="upload" size="50" />
  <br/>
   <input type="submit" value="Upload" />
</form>
package com.eb.rajesign.util;
 @Path("/restwb")
 public class FileResource {

@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(@FormDataParam("upload") InputStream is, @FormDataParam("upload") FormDataContentDisposition formData) {
    System.out.println("I am in service");
    String fileLocation = "D:/TestRaj/" + formData.getFileName();

    try {
        saveFile(is, fileLocation);
        String result = "Successfully File Uploaded on the path " + fileLocation;
        return Response.status(Status.OK).entity(result).build();
    } catch (IOException e) {
        e.printStackTrace();
        return Response.status(Status.INTERNAL_SERVER_ERROR).build();

    }

}

private void saveFile(InputStream is, String fileLocation) throws IOException {

    OutputStream os = new FileOutputStream(new File(fileLocation));
    byte[] buffer = new byte[256];
    int bytes = 0;
    while ((bytes = is.read(buffer)) != -1) {
        os.write(buffer, 0, bytes);
    }
}}