前台JS和后台相应如下:
var username = $("#user_name").val().trim();
var password = $("#password").val();
console.log(username+","+password);
$.ajax({
url:"/Test1224/login.action",
data:{"username":username,"password":password},
dataType:"json",
type:"POST",
success:function(result){
console.log("success");
console.log(result);
}
});
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
super.doPost(req, resp);
System.out.println("enter doPost");
resp.setCharacterEncoding("UTF-8");
resp.setContentType("text/html;charset=UTF-8");
System.out.println(req.getParameter("username")+","+req.getParameter("password"));
PrintWriter pw = resp.getWriter();
Result result = new Result();
result.setFlag(true);
result.setName(req.getParameter("username"));
pw.print(result);
pw.close();
}
错误提示:POST http://127.0.0.1:9080/Test1224/login.action 405 (Method Not Allowed)