@Controller
@RequestMapping(value = "/restaurant")
public class ConsumerChangeInfoController {
private ConsumerChangeInfoService consumerChangeInfoService;
private ConsumerLoginService consumerLoginService;
@RequestMapping(value = "/consumerInfo",method = RequestMethod.PUT)
public String changeInfo(ChangeInfoDto changeInfoDto, HttpSession session, HttpServletRequest request){
String path = session.getServletContext().getRealPath("/images/headPortrait");
String fileName = changeInfoDto.getChooseHeadFile().getOriginalFilename();
String extensionName = fileName
.substring(fileName.lastIndexOf(".") + 1);
String newFileName = String.valueOf(System.currentTimeMillis())
+ "." + extensionName;
File targetFile = new File(path, newFileName);
if(!targetFile.exists()){
targetFile.mkdirs();
}
try {
changeInfoDto.getChooseHeadFile().transferTo(targetFile);
} catch (Exception e) {
e.printStackTrace();
}
String savePath = request.getContextPath()+"/images/headPortrait/"+newFileName;
consumerChangeInfoService.updateInfo((Consumer) session.getAttribute("loginUser"),changeInfoDto,savePath);
Consumer consumer = consumerLoginService.consumerLogin((LoginConsumerDto) session.getAttribute("loginConsumerDto"));
session.setAttribute("loginUser",consumer);
return "redirect:index";
}
<form id="changeInfoForm" action="${pageContext.request.contextPath}/restaurant/consumerInfo" onsubmit="return checkSubmit()" method="post" enctype="multipart/form-data">
<input type="text" placeholder="userName" name="showName" value="${sessionScope.loginUser.showName}"/>
<div class="bubble-box arrow-top" id="showNameBox">
<div class="wrap"></div>
</div>
<img id="showNameIcon" src="${pageContext.request.contextPath}/images/registerIcon/true.png" height="20px" width="20px"/>
<div class="clearfix"> </div>
<input type="text" placeholder="phone" name="phone" value="${sessionScope.loginUser.phone}"/>
<div class="bubble-box arrow-top" id="phoneBox">
<div class="wrap"></div>
</div>
<img id="phoneIcon" src="${pageContext.request.contextPath}/images/registerIcon/true.png" height="20px" width="20px"/>
<div class="clearfix"> </div>
<div id="localImag">
<img id="ImgPr" src="${pageContext.request.contextPath}${sessionScope.loginUser.headPortrait}"/>
</div>
<input type="file" name="chooseHeadFile" id="up" onchange="upload()"/>
<div style="color:#888;">jpg,gif,png,max_size:1M</div>
<span style="color:red" id="errorMessage"></span>
<span id="errMessage" style="color: red;"></span>
<input type="hidden" name="_method" value="PUT">
<div class="send">
<input type="submit" value="Send" name="changeInfoButton">
</div>
</form>
When I use RequestMethod.PUT,there is error HTTP Status 405 - Request method 'POST' not supported in browser,but when I use RequestMethod.POST, there is no error.I have already add in form,and I can get "_method"'s value in controller,is "PUT".I have already add
<filter>
<filter-name>HiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HiddenHttpMethodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
,so where is my error?