java request null_使用AJAX将数据传到后台,但是后台的request为null,该怎么解决

  • Post author:
  • Post category:java


使用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



版权声明:本文为weixin_39569543原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。