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:

<form action="fileUpload" method="post" enctype="multipart/form-data">  
    选择文件:<input type="file" name="file">  
    <input type="submit" value="提交">   
</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代码改成如下:

<form action="fileUpload/" method="post" enctype="multipart/form-data">  
    选择文件:<input type="file" name="file">  
    <input type="submit" value="提交">   
</form>

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



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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值