开发者社区> 问答> 正文

请教!登录功能ajax post请求request.getParameter("username")取值为null

本机和测试服务器都能取到值,发布到正式环境上就取值为null,

js代码:
$.ajax({

            url: 'login.action',
            type: 'POST',
            data: {
                "username": L.inputAccount.val(),
                "password": L.inputPassword.val()
            },
            dataType: 'json',
            catch:true,
            success: function (data) {
                console.log(data);
                $btn.button('reset');
                if (data.result) {
                    //跳转地址
                    window.location.href = "view.action";
                } else {
                    L.errorTip.text(data.msg).show();
                }
                $btn.button('reset');
            },
            error: function () {
                L.errorTip.text('请检查网络或联系后台管理人员!').show();
                $btn.button('reset');
            }
        })

后台代码:

@RequestMapping(value="login.action", method = RequestMethod.POST)

@ResponseBody
public Map<String,Object> login(HttpServletRequest req){
    Map<String,Object> model = new HashMap<String,Object>();
    HttpSession session = req.getSession();
    String username = req.getParameter("username");
    String password = req.getParameter("password");
    resultLog.info("登录信息"+username+"----------"+password);
    Map<String,Object> employeeInfo = service.getEmployeeInfo(username,password);
    if(employeeInfo != null && employeeInfo.size()>0){
        model.put("result", true);
        model.put("msg", "登录成功");
        session.setAttribute("onlineuser", employeeInfo);
        session.setAttribute("username", employeeInfo.get("Name"));
        session.setAttribute("ID",employeeInfo.get("ID"));
    }else{
        model.put("result", false);
        model.put("msg", "用户名或密码错误,请重新填写!");
    }
    return model;
}

展开
收起
xsherlock 2017-06-29 09:20:25 5199 0
1 条回答
写回答
取消 提交回答
  • 遇见你我才知道你对我有多重要。

    检查
    L.inputAccount.val()
    可以先传个固定值看看能否传到后台

    2019-07-17 21:20:40
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载