jsp上传图片报错The request sent by the client was syntactically incorrect.
本人小白 刚做了一个jsp上传图片用springmvc接收
结果报错The request sent by the client was syntactically incorrect.
下面是jsp页面的代码
<form action="/xiangmu/users/uploadfile" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" value="提交"/>
</form>
控制层代码
@RequestMapping(value="/uploadfile",method=RequestMethod.POST)
public String handleFileUpdate(@RequestParam("file") CommonsMultipartFile file,HttpServletRequest req)throws FileUploadException{
long startTime=System.currentTimeMillis();//获取开始时间
PictureService ps=new PictureService();
Picture pic=new Picture();
if(!file.isEmpty()){
try {
String aa=file.getName();
String ppath="D:/pic/"+aa+".jpg";
File ouputimage=new File(ppath);//新建一个文件
try {
file.getFileItem().write(ouputimage);//将上传的文件写入新建的文件中
} catch (Exception e) {
e.printStackTrace();
}
pic.setPpath(ppath);pic.setCreatedate(new Date());pic.setUuid(1);
ps.addPicture(pic);
} catch (Exception e) {
e.printStackTrace();
}
}
long endTime=System.currentTimeMillis();//获取结束时间
System.out.println("上传文件共使用时间:"+(endTime-startTime));
return "/index.jsp";
}
完全不知道原因