您好,我是Web服务的新手。
我想通过泽西上传xml文件,但我在浏览器上出现“HTTP Status 415 - Unsupported Media Type”错误。 我包括的罐子是:
提前致谢。
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