<pre name="code" class="java">/**
* 登录
* @return
*/
public String login() {
HttpServletRequest request= ServletActionContext.getRequest();
User cus = userService.loginByNameAndPassword(login_name,login_password);
if (cus != null && cus.getId() != null) {
request.getSession().setAttribute(WebConfig.CUSTOMER_ID,cus.getId());
request.getSession().setAttribute(WebConfig.CUSTOMER_LOGIN_NAME, cus.getLoginName());
login_result = "['success']";
} else {
login_result = "['error']";
}
return SUCCESS;
}
$(function() { $("div.panel-foot button").click(function() { var login_name = $("input[name='login_name']").val(); var s_password = $("#pwd").val(); if (login_name == null || login_name == '') { alert("请出入用户名"); return false; } if (s_password == null || s_password == '') {alert("请输入密码"); return false; } var password = hex_md5(s_password); $("input[name='login_password']").val(password); var option = { url : "/company/login.action",type : "post",dataType : "json",success : function(result) { var data = eval("(" + result + ")"); if (data == 'success') { location.href = "list.action"; } else { alert("登录失败,用户或密码不正确!"); } } }; $('#login_form').ajaxSubmit(option); return false; }); });
<form id="login_form">
<div class="panel">
<div class="panel-head"><strong>登录<pre name="code" class="html"><!-- 后台查看订单列表-->
<action name="login" class="userAction" method="login">
<result type="json">
<param name="root">login_result</param>
</result>
</action>
<!-- 后台查看订单列表-->
<action name="login" class="userAction" method="login">
<result type="json">
<param name="root">login_result</param>
</result>
</action>