Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc Spring 3:使web应用程序接受multipartfile参数的null参数_Spring Mvc_Exchangewebservices_Multipartform Data - Fatal编程技术网

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)多部分文件文件