登录页面书写,基本操作 login

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>welcom to lvmeihe's world</title>
</head>
<body>
<!-- action的值可以有controller处理,也可以交给servlet处理 -->
<form action="index.action">
<span>账号</span><input type="text" name="userAccount" required="required">
<span>密码</span><input type="password" name="passWord" required="required">
<input type="submit" value="登录">
</form>

<h1>方法2</h1>
<span>账号</span><input type="text" name="userAccount" id="id1" required="required">
<span>密码</span><input type="password" name="passWord" id="id2" required="required">
<input type="button" id="enterIndex">
<script type="text/javascript">
$("#enterIndex").click(function(){
$.ajax({
type: 'post',

usl: 'index.action',

data:{'账号':'value','密码':'value'},

dataType:"JSON",

success: function(){
window.location= 'index.jsp';
}

});

方法2:$.get(url,data,function(){从controller中返回的数据});

方法3:$.post(url,data,function(){从controller中返回的数据});

});
</script>
</body>

</html>

@ResponseBody
@RequestMapping("login")
public String doLogin(HttpServletRequest request, HttpServletResponse response){
String userAccount = request.getParameter("userAccount");
String password = request.getParameter("password");
//根据从页面获取的账号和密码 和数据库中的对比 查看是否匹配
//匹配成功 允许登录并进入主页  
//匹配不成功重新进入登录页/或者注册页(点击密码找回按钮)
if(" ".equals(" ")){
request.setAttribute("error", "登录失败");
}
return "0";
}

方法2

@RequestMapping("index")
public String tests(Map<String,Object> params){
String account = (String) params.get("userAccount");
String password = (String) params.get("password");
//从数据库中查找数据 然后和account password进行比较
return "index";
}

是否登录过?

@RequestMapping("xxx")
public String doIndex(Map<String,Object> params,HttpServletRequest request, HttpServletResponse response){

Set<String> keys = params.keySet();
for (String string : keys) {
System.out.println(string);
}

Cookie[] cookies = request.getCookies();
//判断是否登录过了
if(cookies != null && cookies.length > 0){
for(Cookie cookie : cookies){
String name = cookie.getName();
if(name.equals("login")){
//有login。说明已经登录过了,可以跳转到index.jsp页面
return "index";
}
}
}
//没登录过,就在此返回到登录页面,进行登录
return "login";
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值