Spring mvc Spring 3:使web应用程序接受multipartfile参数的null参数
当前,当文件参数为Spring mvc Spring 3:使web应用程序接受multipartfile参数的null参数,spring-mvc,exchangewebservices,multipartform-data,Spring Mvc,Exchangewebservices,Multipartform Data,当前,当文件参数为null或表单中为空时,web应用程序会抛出一个错误。我甚至检查过文件为空但似乎不起作用的情况。有人知道当表单中的filename字段为空时如何检查案例,而不在web应用程序中抛出错误吗 我正在为控制器使用以下代码。如您所见,我接受一个多部分文件参数,即表单中上载的文件 @RequestMapping(value="/attachment", method=RequestMethod.POST) public String sendAttachment(@RequestHead
null
或表单中为空时,web应用程序会抛出一个错误。我甚至检查过文件为空但似乎不起作用的情况。有人知道当表单中的filename字段为空时如何检查案例,而不在web应用程序中抛出错误吗
我正在为控制器使用以下代码。如您所见,我接受一个多部分文件参数,即表单中上载的文件
@RequestMapping(value="/attachment", method=RequestMethod.POST)
public String sendAttachment(@RequestHeader("Authorization") String authHeader, @RequestParam("to") String to,@RequestParam("cc") String cc,@RequestParam("bcc") String bcc,@RequestParam("subject") String subject,@RequestParam("body") String body, @RequestParam("file") MultipartFile file,@RequestParam("filename") String filename) {
. . .
//here i check if the file is empty...if not empty, then only attach it in the message.
if(!file.isEmpty())
{
msg.getAttachments().addFileAttachment(filename,file.getBytes());
}
. . .
我用来调用此web服务的php文件如下所示:
以下是使用空文件param发送到web服务的表单post参数
$params = array(
'to' => null,
'cc' => null,
'bcc' => "sanjaygir@gmail.com",
'subject' => "hola sanjayg",
'body' => "just testing message service",
'filename'=> "",
'file'=>""
);
我也尝试过使用null:
$params = array(
'to' => null,
'cc' => null,
'bcc' => "sanjaygir@gmail.com",
'subject' => "hola sanjayg",
'body' => "just testing message service",
'filename'=> null,
'file'=>null
);
但它仍然会在服务器中抛出500个错误 尝试将
@RequestParam(“文件”)多部分文件文件更改为@RequestParam(value=“file”,required=false)多部分文件文件