SpringMVC Request method 'GET' not supported 解决办法

错误日志

2015-11-05 00:14:42 [org.springframework.web.servlet.DispatcherServlet]-[DEBUG] DispatcherServlet with name 'springmvc' processing GET request for [/DailyPhoto/fileUpload/]

2015-11-05 00:14:42 [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping]-[DEBUG] Looking up handler method for path /fileUpload/

2015-11-05 00:14:42 [org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver]-[DEBUG] Resolving exception from handler [null]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported

2015-11-05 00:14:42 [org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver]-[DEBUG] Resolving exception from handler [null]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported

2015-11-05 00:14:42 [org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver]-[DEBUG] Resolving exception from handler [null]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported

2015-11-05 00:14:42 [org.springframework.web.servlet.PageNotFound]-[WARN] Request method 'GET' not supported

2015-11-05 00:14:42 [org.springframework.web.servlet.DispatcherServlet]-[DEBUG] Null ModelAndView returned to DispatcherServlet with name 'springmvc': assuming HandlerAdapter completed request handling

2015-11-05 00:14:42 [org.springframework.web.servlet.DispatcherServlet]-[DEBUG] Successfully completed request


JSP form:

  
    选择文件:  
       

Controller:

@RequestMapping(value="/fileUpload", method=RequestMethod.POST)
		public String fileUpload(@RequestParam("file") MultipartFile file) {
			// 判断文件是否为空
			if (!file.isEmpty()) {
				try {
					// 文件保存路径
					String filePath = request.getSession().getServletContext().getRealPath("/") + "upload/"
							+ file.getOriginalFilename();
					// 转存文件
					file.transferTo(new File(filePath));
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			// 重定向
			return "redirect:/list.html";
		}


解决办法:

将JSP代码改成如下:

  
    选择文件:  
       

其实就是在action的值后面增加了一个 “/”,问题就解决了。



转载于:https://my.oschina.net/u/2508148/blog/526045

你可能感兴趣的:(SpringMVC Request method 'GET' not supported 解决办法)