spring-mvc 前端post表单数据到后台,后台没有接收到,并且用HttpServletRequest获取参数列表为空,下面为代码:
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("//"); response.setContentType("text/html"); response.getWriter().println("keke"); response.getWriter().flush(); response.getWriter().close(); return null; } }
我已经调试过无数次了,如果设定为GET方法,然后把参数放在URL上是完全没有问题的,用json提交,配置json转换也是没有问题的,就是默认的POST表单数据有问题,下面是调试工具生成的表单完整报文:
POST /BugTest/rest/demo HTTP/1.1 Host: 127.0.0.1:8080 Content-Type: application/x-www-form-urlencoded Cache-Control: no-cache username=111wqfewrf&password=321&=
一直都是好好的,这么简单的demo,现在突然不行了,好久没写springmvc了,我漏了什么吗?
付费偷看金额在0.1-10元之间
顺便提一下,即使是用springmvc的注解 : RequestParam ,也是取不到的,整个表单数据都是空的
一周热门 更多>