jersey 2.x 文件上传

关键代码:

application.java中

register(MultiPartFeature.class);

前端html中:

<form action="${path}/list/uploadExcel" method="post" enctype="multipart/form-data" accept-charset="utf-8">
	<p>
		<input type="file" name="file" /><br />
	</p>
	<input type="submit" value="上传" />
</form>

服务端(有略微的名称编码问题):

<span style="white-space:pre">	</span>@POST
	@Path("uploadExcel")
	@Consumes(MediaType.MULTIPART_FORM_DATA)
	public String uploadExcel(
			@FormDataParam("file") InputStream fileInputStream,
			@FormDataParam("file") FormDataContentDisposition disposition) {
		String imageName = Calendar.getInstance().getTimeInMillis()
				+ disposition.getFileName();
		//File file = new File("D:\\" + imageName);
		return "import data succeed";
	}



你可能感兴趣的:(文件上传,Restful,jersey)