原帖由 tong0245 于 2009-7-1 14:52 发表
jsp 和 javabean class 都要贴上来
好的。
login.jsp
<%@ page language="java" pageEncoding="gb2312"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
<SCRIPT language=javascript src="<%=request.getContextPath() %>/js/main.js"></SCRIPT>
<link href="<%=request.getContextPath() %>/template/css_red/styles/xzsp.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form method="post" action="login.action">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="128" align="center" background="<%=request.getContextPath() %>/template/css_red/images/login_bg.gif"><img src="<%=request.getContextPath() %>/template/css_red/images/login01.gif" width="626" height="128" /></td>
</tr>
<tr>
<td align="center"><table width="626" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="335"><img src="<%=request.getContextPath() %>/template/css_red/images/login02.gif" width="335" height="322" /></td>
<td align="left" valign="top" background="<%=request.getContextPath() %>/template/css_red/images/login03.gif"><table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="34" height="80"></td>
<td width="24" nowrap="nowrap"></td>
<td width="146"> </td>
</tr>
<tr>
<td></td>
<td>用户名:</td>
<td><input type="text" id="username" name="pageBean.user.username"/></td>
</tr>
<tr>
<td></td>
<td></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>密 码:</td>
<td><input type="password" id="password" name="pageBean.user.password" onkeydown="document.onkeydown();"/></td>
</tr>
<tr>
<td height="30"></td>
<td>
</td>
<td> </td>
</tr>
<tr>
<td></td>
<td></td>
<td><a href="#" onclick="validateNull()"><img src="<%=request.getContextPath() %>/template/css_red/images/login_d.gif" width="61" height="25" border="0" /></a> <a href="#" onclick="clearText();"><img src="<%=request.getContextPath() %>/template/css_red/images/login_c.gif" width="61" height="25" border="0" /></a></td>
</tr>
<tr>
<td colspan='3'>
<div style="overflow:auto;height:60px;width:220px">
<font color="red">
<s:fielderror />
<br>
<s:actionerror/>
</font>
</div>
</td>
</tr>
<tr>
<td colspan='3'>
<font color="">
<a href="download/Silverlight.exe" target=_blank><u>常用下载:统计分析显示控件下载</u></a>
</font>
</td>
</tr>
</table></td>
</tr>
<tr>
<td height="50" colspan="2" align="center"><table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center"></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</form>
</body>
</html>
<script>
function document.onkeydown() //网页内按下回车触发
{
if(event.keyCode==13)
{
validateNull();
return false;
}
}
function validateNull(){
if(document.getElementById('username').value==null||document.getElementById('username').value==""||document.getElementById('username').value==undefined){
alert('用户名不能为空!');
}else if(document.getElementById('password').value==null||document.getElementById('password').value==""||document.getElementById('password').value==undefined){
alert('密码不能为空!');
}else{
document.forms[0].submit();
}
}
function clearText(){
document.getElementById('username').value="";
document.getElementById('password').value="";
}
</script>
loginBean
public class LoginBean
{
public LoginBean()
{
}
public String getReLoginFlag()
{
return reLoginFlag;
}
public void setReLoginFlag(String reLoginFlag)
{
this.reLoginFlag = reLoginFlag;
}
public boolean isLoginFlag()
{
return loginFlag;
}
public void setLoginFlag(boolean loginFlag)
{
this.loginFlag = loginFlag;
}
public SysUser getUser()
{
return user;
}
public void setUser(SysUser user)
{
this.user = user;
}
private SysUser user;
private boolean loginFlag;
private String reLoginFlag;
}
loginTransactionimpl类
public class LoginTransactionImpl
implements ILoginTransaction
{
public LoginTransactionImpl()
{
}
public List login(LoginBean pageBean)
throws Exception
{
SysUser suser=pageBean.getUser();
String username=suser.getUsername();
String pswd=suser.getPassword();
List userList = userDao.getUserByUsernameAndPasswordAndState(pageBean.getUser().getUsername(), pageBean.getUser().getPassword());
return userList;
}
public List getMenuListByUsername(String username)
throws Exception
{
List tempUserList = userDao.getUserByUsername(username);
if(tempUserList == null || tempUserList.size() == 0)
throw new FuLongException((new StringBuilder(String.valueOf(username))).append(" \u4E0D\u5B58\u5728!").toString());
if(1 != tempUserList.size())
throw new FuLongException((new StringBuilder("\u7528\u6237:")).append(username).append(" \u5728\u6570\u636E\u5E93\u4E2D\u4E0D\u662F\u552F\u4E00\u7684!").toString());
SysUser user = (SysUser)tempUserList.get(0);
List tempSysUserRole = sysUserRoleDao.getSysUserRoleByUserId(user.getId());
if(tempSysUserRole == null || tempSysUserRole.size() == 0)
throw new FuLongException((new StringBuilder("\u7528\u6237\uFF1A")).append(username).append(" \u6CA1\u6709\u5206\u914D\u6743\u9650\uFF01").toString());
if(1 != tempSysUserRole.size())
throw new FuLongException((new StringBuilder("\u7528\u6237\uFF1A")).append(username).append(" \u6743\u9650\u4E0D\u552F\u4E00\uFF01").toString());
SysUserRole sysUserRole = (SysUserRole)tempSysUserRole.get(0);
List tempPermissionList = permissionDao.getPermissionByRoleId(sysUserRole.getRoleId());
if(tempPermissionList == null || tempPermissionList.size() == 0)
throw new FuLongException((new StringBuilder("\u7528\u6237\uFF1A")).append(username).append(" \u6240\u5728\u6743\u9650\u6CA1\u6709\u5206\u914D\u83DC\u5355").toString());
List finalMenuList = new ArrayList();
for(int i = 0; i < tempPermissionList.size(); i++)
{
SysPermission tempPermission = (SysPermission)tempPermissionList.get(i);
List menuList = menuDao.getMenuByMenuCode(tempPermission.getModuleCode());
if(menuList == null || menuList.size() == 0)
throw new FuLongException((new StringBuilder("\u6CA1\u6709\u83DC\u5355\u7684code\u662F:")).append(tempPermission.getModuleCode()).toString());
if(1 != menuList.size())
throw new FuLongException((new StringBuilder("moduleCode:")).append(tempPermission.getModuleCode()).append(" \u4E0D\u552F\u4E00").toString());
SysMenu menu = (SysMenu)menuList.get(0);
finalMenuList.add(menu);
}
return finalMenuList;
}
public ISysUserDao getUserDao()
{
return userDao;
}
public void setUserDao(ISysUserDao userDao)
{
this.userDao = userDao;
}
public ISysMenuDao getMenuDao()
{
return menuDao;
}
public void setMenuDao(ISysMenuDao menuDao)
{
this.menuDao = menuDao;
}
public ISysPermissionDao getPermissionDao()
{
return permissionDao;
}
public void setPermissionDao(ISysPermissionDao permissionDao)
{
this.permissionDao = permissionDao;
}
public ISysUserRoleDao getSysUserRoleDao()
{
return sysUserRoleDao;
}
public void setSysUserRoleDao(ISysUserRoleDao sysUserRoleDao)
{
this.sysUserRoleDao = sysUserRoleDao;
}
private ISysUserDao userDao;
private ISysMenuDao menuDao;
private ISysPermissionDao permissionDao;
private ISysUserRoleDao sysUserRoleDao;
}
XML配置还用贴吗? |