spring-mvc 前端post表單數(shù)據(jù)到后臺(tái),后臺(tái)沒有接收到,并且用HttpServletRequest獲取參數(shù)列表為空,下面為代碼:
web.xml:
<servlet> <servlet-name>embers</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:conf/embers-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> <async-supported>true</async-supported> </servlet><servlet-mapping> <servlet-name>embers</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping>
mvc配置文件:
<context:component-scan base-package="embers.blog.controller" />
controller:
@Controller public class BugTestController { @RequestMapping(value="/demo",method=RequestMethod.POST) public String demo(HttpServletRequest request,HttpServletResponse response) throws IOException{ System.out.println(request.getParameterMap()); System.out.println(request.getParameter("username")); System.out.println(request.getParameter("password")); System.out.println(request.getContentType()); System.out.println("http://"); response.setContentType("text/html"); response.getWriter().println("keke"); response.getWriter().flush(); response.getWriter().close(); return null; } }
我已經(jīng)調(diào)試過(guò)無(wú)數(shù)次了,如果設(shè)定為GET方法,然后把參數(shù)放在URL上是完全沒有問題的,用json提交,配置json轉(zhuǎn)換也是沒有問題的,就是默認(rèn)的POST表單數(shù)據(jù)有問題,下面是調(diào)試工具生成的表單完整報(bào)文:
POST /BugTest/rest/demo HTTP/1.1 Host: 127.0.0.1:8080 Content-Type: application/x-www-form-urlencoded Cache-Control: no-cacheusername=111wqfewrf&password=321&=
一直都是好好的,這么簡(jiǎn)單的demo,現(xiàn)在突然不行了,好久沒寫springmvc了,我漏了什么嗎?