我想提交一個表單到控制器在使用java春天,在下面的代碼中我通過以下方式成功檢索文件元素,但沒有得到如何檢索其他元素(短名稱和全部名)值。 請幫我一把。如何檢索在控制器中的表單元素在java
<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字符串shortName'和'@RequestParam字符串fullName'? – sp00m
是的,我確實嘗試了你的語法,但是這有助於幫助。感謝您的回覆。 – b22