SSH ajax登录

登录页面

<form action="" method="post" id="frm">
		<table border="1" align="center">
			<caption>
				<h1>部门表登录</h1>
			</caption>
			<tr>
				<td>dname</td>
				<td><input name="dept.dname" />
				</td>
			</tr>

			<tr>
				<td>loc</td>
				<td><input name="dept.loc" />
				</td>
			</tr>

			<tr align="center">
				<!-- 必须改成普通按钮! -->
				<td colspan="2"><input type="button" value="登录" id="button" />
					<input type="reset" value="重置" />
				</td>
			</tr>

			</form>


脚本页面

$(function() {

	// 单击事件
	$("#button").click(function() {
		// jQuery.post(url, [data], [callback], [type])
		$.post("login.action", $("#frm").serialize(), function(data) {
			if(data==1){
				document.location.href="index.jsp";  //重定向
			}else{
				$("body").prepend("<div style='color:red;text-align:center'>用户名或密码错误!</div>");
			}

		}, "json");

	});

});


Action控制器

	public String ajax_login() throws Exception {
		// 调用方法
		dept = biz.findIsLogin(dept);
		// 判断
		if (dept != null) {
			session.put("depts", dept);
			result = "1"; // 登录成功
		} else {
			result = "0"; // 登录失败
		}

		return SUCCESS;
	}

	Map<String, Object> session;

	@Override
	public void setSession(Map<String, Object> session) {
		// TODO Auto-generated method stub
		this.session = session;
	}

显示结果:









  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值