Ajax实现用户名及密码自检
Ajax
用户名和密码实现自检
1、添加jQuery支持
在Web下创建statics包,在statics包下创建js包,导入jQuery.js
2、配置applicationContext.xml文件
3、controller层
public class AjaxController {
/**
@RequestMapping("/t1")
public String test() {
return "hello";
}
@RequestMapping("/a1")
public void a1(String name, HttpServletResponse httpServletResponse) {
System.out.println(name);
if ("baidu".equals(name)) {
System.out.println("true");
} else {
System.out.println("false");
}
}
@RequestMapping("/a2")
public List a2() {
List userList = new ArrayList();
userList.add(new User("java", 1, "male"));
userList.add(new User("css", 2, "male"));
userList.add(new User("js", 3, "female"));
return userList;
}
**/
@RequestMapping("/a3")
public String a3(String name, String pwd) {
String msg = "";
if (name != null) {
if ("admin".equals(name)) {
msg = "ok";
} else {
msg = "error";
}
}
if (pwd != null) {
if ("123456".equals(pwd)) {
msg = "ok";
} else {
msg = "error";
}
}
return msg;
}
}
4、前端页面
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
Title
用户名:
密码:
原文:https://www.cnblogs.com/rongchengbanxia/p/14919880.html