使用AJAX将一个数据传到后台,但是java后台的request为null,无法getParameter,该怎么解决?
JS代码:
callback: {
message: ‘用户名已被占用’,
callback: function (value, validator) {
var res = true;
var checkvalue = $(“#username”).val();
if(checkvalue.length > 5){
$.ajax({
url: ‘${pageContext.request.contextPath}/user/userCheckExist.vk’,
type: ‘post’,
dataType: ‘text’,
async: false,
data: {‘checkvalue’: checkvalue},
success: function (responseText) {
alert(responseText);
if (responseText != ‘success’) {
res = false;
}
}
}
后台代码:
public void userCheckExist(@RequestParam(value = “checkvalue”, required = false)HttpServletRequest request,HttpServletResponse response) throws IOException{
String sss = “”;
response.setContentType(“text/html;charset=UTF-8”);
try{
String checkName = request.getParameter(“checkvalue”);// 因为request为空,所以此处报错
// ··· ···
}catch (Exception e) {
e.printStackTrace();
response.getWriter().write(“success”);
}
response.getWriter().write(“success”);
return;
}
报错信息为:
DEBUG [http-nio-8080-exec-6] – DispatcherServlet with name ‘mybatis’ processing POST request for [/VenkSOS/user/userCheckExist.vk]
DEBUG [http-nio-8080-exec-6] – Looking up handler method for path /user/userCheckExist.vk
DEBUG [http-ni