spring-mvc 前端post表单数据到后台,后台没有接收到,并且用HttpServletRequest获取参数列表为空,下面为代码:
web.xml:
embers
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:conf/embers-mvc.xml
1
true
embers
/rest/*
mvc配置文件:
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了,我漏了什么吗?
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
表单呢?确认那些字段写在form里了?