用户登陆功能

1 web.xml

<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>

2

<s:form METHOD="post" NAME="actForm" action="user_login" namespace="/">
<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">
<font color="red">
<s:actionerror/>
</font>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 width=100%>
<TR>
<TD width=45 CLASS="Subject"><IMG BORDER="0" SRC="${pageContext.request.contextPath}/style/blue/images/login/userId.gif" /></TD>
<TD><INPUT SIZE="20" CLASS="TextField" TYPE="text" NAME="loginName" /></TD>
<TD ROWSPAN="2" STYLE="padding-left:10px;"><INPUT TYPE="image" 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><INPUT SIZE="20" CLASS="TextField" TYPE="password" NAME="password" /></TD>
</TR>
</TABLE>
</DIV>
<DIV ID="CopyRight"><A HREF="javascript:void(0)">&copy; 2010 版权所有 itcast</A></DIV>
</DIV>
</DIV>
</s:form>

3

<action name="user_*" class="userAction" method="{1}">

4 

public String login(){
User user = userService.login(model);

if(user != null){
//登录成功
//将登录用户放入Session
ServletActionContext.getRequest().getSession().setAttribute("loginUser", user);
return "home";
}else{
//登录失败
//设置错误提示
this.addActionError("用户名或者密码错误!");
return "loginUI";
}
}

5

/**
* 用户登录
*/
public User login(User model) {
String hql = "FROM User u WHERE u.loginName = ? AND u.password = ?";
Query query = this.getSession().createQuery(hql);
query.setParameter(0, model.getLoginName());
query.setParameter(1, MD5Utils.md5(model.getPassword()));
List<User> list = query.list();
if(list != null && list.size() > 0){
return list.get(0);
}
return null;
}

6

<result name="home">/WEB-INF/jsp/home/index.jsp</result>
<result name="loginUI">/login.jsp</result>

7

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
<%@include file="/WEB-INF/jsp/public/header.jsp" %>
</head>
<frameset rows="100,*,25" framespacing="0" border="0" frameborder="0">
<frame src="${pageContext.request.contextPath }/home_top.do" name="TopMenu" scrolling="no" noresize />
<frameset cols="180,*" id="resize">
<frame noresize name="menu" src="${pageContext.request.contextPath }/home_left.do" scrolling="yes" />
<frame noresize name="right" src="${pageContext.request.contextPath }/home_right.do" scrolling="yes" />
</frameset>
<frame noresize name="status_bar" scrolling="no" src="${pageContext.request.contextPath }/home_bottom.do" />
</frameset>
<noframes>
</noframes>
</html>

猜你喜欢

转载自www.cnblogs.com/tianluguilai/p/9449272.html
今日推荐