登陆、注销

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>


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值