【发布时间】:2014-03-19 16:51:15
【问题描述】:
我正在尝试使用 java spring 向控制器提交表单,在以下代码中,我正在通过以下方式成功检索文件元素,但没有获得如何检索其他元素(短名和全名)值。 请帮帮我。
<body>
<div style="text-align: center; margin-top: 60px;">
<form action="upload" enctype="multipart/form-data">
<input type="hidden" id="shortName" name="michael">
<input type="hidden" id="fullName" name="michael jackson">
Select file:
<input type="file" name="dataFile" id="fileAttachment"/><br/><br/>
<div style="text-align: center; margin-top: 100px;">
<input style="cursor: pointer;" onmouseover="" onclick="uploadAttachment()" class="dialogbox" type="submit" value="Upload Report" />
</div>
</form>
</div>
</body>
控制器端代码:
@RequestMapping(value = "upload", method=RequestMethod.POST)
public void upload(HttpServletRequest request, HttpServletResponse response,
@RequestPart("dataFile") MultipartFile file
){
System.out.println(file.getSize());
}
【问题讨论】:
-
你试过
@RequestParam String shortName和@RequestParam String fullName吗? -
是的,我确实尝试过你的语法,但它有帮助。感谢您的回复。
标签: java spring multipartform-data form-data