使用Jersey和tomcat 7选择后单击上载按钮时REST服务中的内部服务器错误

时间:2014-05-01 02:55:15

标签: java rest maven tomcat jersey

我在上传文件时遇到问题我正在尝试通过html格式上传文件我从驱动器中选择了一个文件但是当我按上传时它给出内部服务器错误这个是我按下上传按钮的情况,但是当我单独运行html和Post方法调用时抛出方法不允许错误根据我的每件事情都可以,所有的依赖关系已被添加路径已经构建和服务器正在使用简单的GET方法请帮帮我

                   **HERE is The Code**



            package com.mongo.maven;

    import java.io.File;
    import java.io.FileNotFoundException;
    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.GET;
    import javax.ws.rs.POST;
    import javax.ws.rs.Path;
    import javax.ws.rs.Produces;
    import javax.ws.rs.core.MediaType;
    import javax.ws.rs.core.Response;

    import com.sun.jersey.core.header.FormDataContentDisposition;
    import com.sun.jersey.multipart.FormDataParam;

    @Path("/hello")
    public class MongoServer {

            private static final String SERVER_UPLOAD_LOCATION_FOLDER = "C://Users/Waseem/Desktop/Upload_Files/";



            @GET
            @Produces(MediaType.TEXT_PLAIN)
            public Response Getdata() {
                String message="hello Pakistan";
                return Response.status(200).entity(message).build();
            }



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

                String filePath = SERVER_UPLOAD_LOCATION_FOLDER+ contentDispositionHeader.getFileName();

                // save the file to the server

                try{
                    saveFile(fileInputStream, filePath);
                }
                catch(IOException ee){
                    return Response.status(400).entity(ee).build();
                }


                String output = "File saved to server location : " + filePath;

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

            }

            // save uploaded file to a defined location on the server

            private void saveFile(InputStream uploadedInputStream, String serverLocation) throws FileNotFoundException , IOException {



                    OutputStream outpuStream = new FileOutputStream(new File(serverLocation));
                    int read = 0;
                    byte[] bytes = new byte[1024];
                    outpuStream = new FileOutputStream(new File(serverLocation));
                    while ((read = uploadedInputStream.read(bytes)) != -1) {
                        outpuStream.write(bytes, 0, read);
                    }
                    outpuStream.flush();
                    outpuStream.close();


            }
    }

**这是POM文件"

<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.first.Jersey</groupId>
      <artifactId>MongodbMaven</artifactId>
      <packaging>war</packaging>
      <version>0.0.1-SNAPSHOT</version>
      <name>MongodbMaven Maven Webapp</name>
      <url>http://maven.apache.org</url>
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3</version>
        </dependency>

        <dependency>
                <groupId>org.mongodb</groupId>
                <artifactId>mongo-java-driver</artifactId>
                <version>2.4</version>
            </dependency>
            <dependency>
                <groupId>com.sun.jersey</groupId>
                <artifactId>jersey-server</artifactId>
                <version>1.8</version>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
                <version>3.0.1</version>
            </dependency>
            <dependency>
                <groupId>com.sun.jersey.contribs</groupId>
                <artifactId>jersey-multipart</artifactId>
                <version>1.8</version>
            </dependency>

      </dependencies>
      <repositories>
            <repository>
                <id>maven2-repository.java.net</id>
                <name>Java.net Repository for Maven</name>
                <url>http://download.java.net/maven/2/</url>
                <layout>default</layout>
            </repository>
        </repositories>

      <build>
        <finalName>MongodbMaven</finalName>
      </build>
    </project>
  

在POST方法上我得到了

方法HTTP状态405 - 不允许的方法 类型状态报告 消息方法不允许 description对于请求的资源,不允许使用指定的HTTP方法。 Apache Tomcat / 7.0.50

  

此错误   以下是我在控制台中的一些内容

May 02, 2014 6:31:21 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files (x86)\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files (x86)/Java/jre7/bin/client;C:/Program Files (x86)/Java/jre7/bin;C:/Program Files (x86)/Java/jre7/lib/i386;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;c:\Program Files (x86)\Intel\iCLS Client\;c:\Program Files\Intel\iCLS  Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\ATI  Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Java\jdk1.7.0_10\bin;D:\Maven\apache-maven-3.1.1\bin;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL  SDK\2.0\bin\x64;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;E:\eclipse;;.
May 02, 2014 6:31:21 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:MongodbMaven' did not find a matching property.
May 02, 2014 6:31:21 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
May 02, 2014 6:31:21 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
May 02, 2014 6:31:21 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 528 ms
May 02, 2014 6:31:21 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
May 02, 2014 6:31:21 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.50
May 02, 2014 6:31:22 AM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO:validateJarFile(E:\Development\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\MongodbMaven\WEB-INF\lib\javax.servlet-api-3.0.1.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
May 02, 2014 6:31:22 AM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:com.mongo.maven
May 02, 2014 6:31:22 AM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:class com.mongo.maven.MongoServer
May 02, 2014 6:31:22 AM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
May 02, 2014 6:31:22 AM com.sun.jersey.server.impl.application.WebApplicationImpl_initiate
INFO: Initiating Jersey application, version 'Jersey: 1.8 06/24/2011 12:17 PM'
May 02, 2014 6:31:23 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
May 02, 2014 6:31:23 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
May 02, 2014 6:31:23 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1631 ms

0 个答案:

没有答案