上传xml文件时,使用jersey获取“HTTP Status 415 - Unsupported Media Type”错误

时间:2018-03-22 10:47:18

标签: java jersey

您好,我是Web服务的新手。

我想通过泽西上传xml文件,但我在浏览器上出现“HTTP Status 415 - Unsupported Media Type”错误。 我包括的罐子是:

  1. com.sun.jersey.jersey核-1​​.4.0
  2. com.sun.jersey.jersey - 服务器 - 1.4.0
  3. javax.ws.rs
  4. 球衣束-1.7
  5. Jersey的JSON-1.4
  6. Jersey的多-1.4
  7. 杰克逊 - 注解-2.3.2
  8. 杰克逊 - 芯 - 2.3.2
  9. 杰克逊 - 数据绑定-2.3.2
  10. 杰克逊 - JAXRS碱基2.3.2
  11. 杰克逊 - JAXRS-JSON-提供商-2.3.2
  12. 杰克逊模块-JAXB的注解-2.3.2
  13. 球衣实体过滤-2.17
  14. Jersey的媒体JSON-杰克逊-2.17
  15. 提前致谢。

    Jsp代码是:

    <%@taglib uri="http://www.springframework.org/tags" prefix="spring"%> 
    <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <link rel="stylesheet" type="text/css" href="Resources_CSS_JS/Common.css"/>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>GenrateView JSP File</title>
    </head>
    <body>
           <form:form id="FileM" modelAttribute="FileM" action="rest/welcometowebservice/uploadfile" method="post" enctype="multipart/form-data">
                     <div  style="text-align: center;" class="centerXML">
                            <form:label  path="xmlfileName">Select File: </form:label>
                            <form:input  path="xmlfileName"    name="xmlfileName" id="xmlfileName" class="text" type="file"/><br>
                            <form:errors path="xmlfileName"    cssClass = "error" /><br>
    
                            <input type="submit"  value ="UploadFile On server.!"/>
                    </div>  
    
     <!-- ********* Below code showing error message from controller if any***********..... -->                
                    <form:errors path="*" />
                       <c:if test="${not empty message}">
                       <h4 style="font-style: italic; color: red;">${message}</h4>
                       </c:if>  
     <!-- ********* Above code showing error message from controller if any************..... -->                              
          </form:form>
    </body>
    </html>
    

    控制器代码是:

    @Path("/welcometowebservice")  
    public class XmlToHtml_Server {
    
        // This method is called if HTML and XML is not requested  
    
        @POST  
        @Path("/uploadfile")  
        @Consumes(MediaType.MULTIPART_FORM_DATA)  
        public Response uploadFile(@FormDataParam("xmlfileName") InputStream uploadedInputStream,  
                                   @FormDataParam("xmlfileName") FormDataContentDisposition fileDetail) 
        {  
                String fileLocation = "D:\\HomeProjectFiles\\HomeUplodedXMLFiles" + fileDetail.getFileName();  
                        //saving file  
                try {  
                    FileOutputStream out = new FileOutputStream(new File(fileLocation));  
                    int read = 0;  
                    byte[] bytes = new byte[1024];  
                    out = new FileOutputStream(new File(fileLocation));  
                    while ((read = uploadedInputStream.read(bytes)) != -1) {  
                        out.write(bytes, 0, read);  
                    }  
                    out.flush();  
                    out.close();  
                } catch (IOException e) {e.printStackTrace();}  
                String output = "File successfully uploaded to : " + fileLocation;  
                return Response.status(200).entity(output).build();  
            }  
    }
    

    控制台输出是: 错误[STDERR] 2018年3月22日下午4:04:09 com.sun.jersey.spi.container.ContainerRequest getEntitySEVERE:Java类com.sun.jersey.multipart.FormDataMultiPart和Java类类com的消息体读取器。 sun.jersey.multipart.FormDataMultiPart和MIME媒体类型multipart / form-data; boundary = ------ 7e218e9170c82未找到ERROR [STDERR] 22 Mar,2018 4:04:09 PM com.sun.jersey.spi .container.ContainerRequest getEntity

0 个答案:

没有答案