登陆、注销
2014-03-24 14:29
134 查看
loginUI.jsp
<!-- 显示表单 --><s:form action="user_login" focusElement="loginNameInput">
<div id="CenterAreaBg">
<div id="CenterArea">
<div id="LogoImg"><img border="0" src="${pageContext.request.contextPath}/style/blue/images/logo.png" /></div>
<div id="LoginInfo">
<table BORDER=0 CELLSPACING=0 CELLPADDING=0 width=100%>
<tr>
<td colspan="3"><!-- 显示错误 -->
<font color="red"><s:fielderror/></font>
</td>
</tr>
<tr>
<td width=45 class="Subject"><img border="0" src="${pageContext.request.contextPath}/style/blue/images/login/userId.gif" /></td>
<td>
<s:textfield name="loginName" size="20" tabindex="1" cssClass="TextField required" id="loginNameInput" />
</td>
<td rowspan="2" style="padding-left:10px;">
<input type="image" tabindex="3" src="${pageContext.request.contextPath}/style/blue/images/login/userLogin_button.gif" />
</td>
</tr>
<tr>
<td class="Subject"><img border="0" src="${pageContext.request.contextPath}/style/blue/images/login/password.gif" /></td>
<td><s:password name="password" id="aa" size="20" tabindex="2" showPassword="false" cssClass="TextField required" /></td>
</tr>
</table>
</div>
<div id="CopyRight"><a href="javascript:void(0)">© 2010 版权所有 </a></div>
</div>
</div>
</s:form>
UserAction.java
/**登陆*/public String login() throws Exception{
User user = userService.findByLoginNameAndPassword(model.getLoginName(),model.getPassword());
if(user == null){
addFieldError("login", "用户名或密码不正确");
return "loginUI" ;
}else{
//登陆用户
ActionContext.getContext().getSession().put("user", user);
return "toIndex" ;
}
}
/**注销*/
public String logOut() throws Exception{
ActionContext.getContext().getSession().remove("user");
return "logOut" ;
}
UserServiceImpl.java
public User findByLoginNameAndPassword(String loginName, String password) {//使用密码的MD5摘要进行对比
String md5Digest = DigestUtils.md5Hex(password);
return (User) getSession().createQuery(//
"FROM User u WHERE u.loginName=? AND u.password=?")//
.setParameter(0, loginName)//
.setParameter(1, md5Digest)//
.uniqueResult();
}
struts.xml
<!-- 用户管理 -->
<action name="user_*" class="userAction" method="{1}">
<result name="list">/WEB-INF/jsp/userAction/list.jsp</result>
<result name="toList" type="redirectAction">user_list</result>
<result name="saveUI">/WEB-INF/jsp/userAction/saveUI.jsp</result>
<result name="loginUI">/WEB-INF/jsp/userAction/loginUI.jsp</result>
<result name="logOut">/WEB-INF/jsp/userAction/logout.jsp</result>
<result name="toIndex" type="redirect">/index.jsp</result>
</action>
相关文章推荐
- Struts2保存登陆信息和注销功能例子
- 【django4】简单注册/登陆/注销功能
- Oracle 学习笔记 登陆和注销
- django.contrib.auth登陆注销学习
- 去除XP系统的登陆和注销对话框的办法
- 安卓App注销登陆实现
- asp.net做的网站账号登陆后注销不管用了
- servlet 登陆注销案例
- windows XP系统中,修改帐户的登陆和注销方式时,提示修改不了的问题!
- HTML框架集,用户注销从新窗体打开.链接登陆页面. .
- 服务器日志出现大量ANONYMOUS LOGON登陆/注销记录的解决方案
- python 04 用户注册、注销、登陆
- JavaWeb基于Session实现的用户登陆注销方法示例
- Android WebView 实现同步登陆和注销登录
- android项目中注销或者退出登陆功能
- win2000远程桌面登陆。断开?注销?直接关闭远程桌面窗口?各有什么区别?谁能给个权威的答案?
- 系统登陆后自动注销不能正常登录系统(一)
- python 04 用户注册、注销、登陆
- android 注销到登陆界面实现
- Linux编程实践——用户登陆注销的记录者