基于SSH2的OA项目1.1_20161207_业务开发

1.1建立用户的pojo模型

建立user.java

 package org.guangsoft.pojo;

 import java.util.HashSet;
import java.util.Set; /**
* 用户的pojo类
* @author guanghe
*
*/
public class User
{
//用户的基本属性
private Integer uid;
private String username;
private String password;
private String sex;
private String email;
private String phone; //描述用户和角色的关系(一个用户对应多个角色)
private Set<Role> roles = new HashSet<Role>();
//描述用户和部门的关系(多个用户对应一个部门)
private Dept dept = new Dept(); public Integer getUid()
{
return uid;
}
public void setUid(Integer uid)
{
this.uid = uid;
}
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
public String getSex()
{
return sex;
}
public void setSex(String sex)
{
this.sex = sex;
}
public String getEmail()
{
return email;
}
public void setEmail(String email)
{
this.email = email;
}
public String getPhone()
{
return phone;
}
public void setPhone(String phone)
{
this.phone = phone;
}
public Set<Role> getRoles()
{
return roles;
}
public void setRoles(Set<Role> roles)
{
this.roles = roles;
}
public Dept getDept()
{
return dept;
}
public void setDept(Dept dept)
{
this.dept = dept;
} }

部门pojo

 package org.guangsoft.pojo;

 import java.util.HashSet;
import java.util.Set; /**
* 定义部门的pojo类
* @author guanghe
*
*/
public class Dept
{
//基本属性
private Integer did;
private String dname;
private String ddesc; //描述部门和用户的关系(一个部门对应多个用户)
private Set<User> users = new HashSet<User>(); public Integer getDid()
{
return did;
}
public void setDid(Integer did)
{
this.did = did;
} public String getDname()
{
return dname;
}
public void setDname(String dname)
{
this.dname = dname;
}
public String getDdesc()
{
return ddesc;
}
public void setDdesc(String ddesc)
{
this.ddesc = ddesc;
}
public Set<User> getUsers()
{
return users;
}
public void setUsers(Set<User> users)
{
this.users = users;
} }

角色的pojo

 package org.guangsoft.pojo;
import java.util.HashSet;
import java.util.Set;
/**
* 定义角色的pojo类
* @author guanghe
*/
public class Role
{
//基本属性
private Integer rid;
private String rname;
private String rdesc; //描述角色和用户的关系
private Set<User> users = new HashSet<User>(); public Integer getRid()
{
return rid;
}
public void setRid(Integer rid)
{
this.rid = rid;
}
public String getRname()
{
return rname;
}
public void setRname(String rname)
{
this.rname = rname;
}
public String getRdesc()
{
return rdesc;
}
public void setRdesc(String rdesc)
{
this.rdesc = rdesc;
}
public Set<User> getUsers()
{
return users;
}
public void setUsers(Set<User> users)
{
this.users = users;
}
}

1.2建立pojo的映射文件

User.hbm.xml

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="org.guangsoft.pojo">
<class name="User" table="t_user">
<id name="uid" column="uid" type="java.lang.Integer">
<generator class="native"></generator>
</id>
<property name="username" column="username" type="java.lang.String"></property>
<property name="password" column="password" type="java.lang.String"></property>
<property name="email" column="email" type="java.lang.String"></property>
<property name="phone" column="phone" type="java.lang.String"></property>
<property name="sex" column="sex" type="java.lang.String"></property>
<!-- 描述用户和角色的关系 -->
<set name="roles" table="user_role">
<key column="uid"></key>
<many-to-many class="Role" column="rid"/>
</set>
<!-- 描述部门和用户的关系 -->
<many-to-one name="dept" class="Dept" column="did"/>
</class>
</hibernate-mapping>

Role.hbm.xml

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="org.guangsoft.pojo">
<class name="Role" table="t_role">
<id name="rid" column="rid" type="java.lang.Integer">
<generator class="native"></generator>
</id>
<property name="rname" column="rname" type="java.lang.String"></property>
<property name="rdesc" column="rdesc" type="java.lang.String"></property>
<set name="users" table="user_role" inverse="true">
<key column="rid"></key>
<many-to-many class="User" column="uid"></many-to-many>
</set>
</class>
</hibernate-mapping>

Dept.hbm.xml

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="org.guangsoft.pojo">
<class name="Dept" table="t_dept">
<id name="did" column="did" type="java.lang.Integer">
<generator class="native"></generator>
</id>
<property name="dname" column="dname" type="java.lang.String"></property>
<property name="ddesc" column="ddesc" type="java.lang.String"></property>
<!-- 描述部门和用户的关系 -->
<set name="users" inverse="true">
<key column="did"></key>
<one-to-many class="User"/>
</set>
</class>
</hibernate-mapping>

1.3定义Dao接口

定义UserDao

 package org.guangsoft.dao;

 import java.util.List;

 import org.guangsoft.pojo.User;
/**
* 完成用户数据的访问
* @author guanghe
*/
public interface UserDao
{
//添加用户数据
public void saveUser(User user);
//查询用户列表
public List<User> getAllUsers();
//删除用户
public void deleteUser(User user);
//修改用户
public void updateUser(User user);
//根据id获取用户
public User getUserById(User user);
}

定义RoleDao

 package org.guangsoft.dao;

 import java.util.List;

 import org.guangsoft.pojo.Role;
/**
* 完成角色数据访问
* @author guanghe
*
*/
public interface RoleDao
{
public List<Role> getAllRoles();
}

定义DeptDao

 package org.guangsoft.dao;

 import java.util.List;

 import org.guangsoft.pojo.Dept;
/**
* 实现部门的数据访问
* @author guanghe
*
*/
public interface DeptDao
{
//查询所有部门数据
public List<Dept> getAllDepts();
}

1.4建立Dao接口的实现类

定义UserDaoImpl

 package org.guangsoft.dao.impl;

 import java.util.List;

 import org.guangsoft.dao.UserDao;
import org.guangsoft.pojo.Dept;
import org.guangsoft.pojo.User;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository; /**
* 建立dao接口实现类
* extends HibernateDaoSupport
* 完成dao中获得session
* @author guanghe
*/
@Repository
public class UserDaoImpl extends HibernateDaoSupport implements UserDao
{
/**
* 给父类注入sessionFactory通过自动装配
* @param sessionFactory
*/
@Autowired
public void setSessionFactoryAutoWire(SessionFactory sessionFactory)
{
super.setSessionFactory(sessionFactory);
} /**
* 添加用户
*/
@Override
public void saveUser(User user)
{
super.getHibernateTemplate().save(user);
} @Override
public List<User> getAllUsers()
{
return (List<User>)super.getHibernateTemplate().find("from User");
} @Override
public void deleteUser(User user)
{
super.getHibernateTemplate().delete(user);
} @Override
public void updateUser(User user)
{
super.getHibernateTemplate().update(user);
} @Override
public User getUserById(User user)
{
return (User) super.getHibernateTemplate().find("from User u where u.uid=?", user.getUid()).get(0);
} }

定义RoleDaoImpl

 package org.guangsoft.dao.impl;

 import java.util.List;

 import org.guangsoft.dao.RoleDao;
import org.guangsoft.pojo.Dept;
import org.guangsoft.pojo.Role;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository; /**
* 建立dao接口实现类
* extends HibernateDaoSupport
* 完成dao中获得session
* @author guanghe
*
*/
@Repository
public class RoleDaoImpl extends HibernateDaoSupport implements RoleDao
{
/**
* 给父类注入sessionFactory通过自动装配
* @param sessionFactory
*/
@Autowired
public void setSessionFactoryAutoWire(SessionFactory sessionFactory)
{
super.setSessionFactory(sessionFactory);
} @Override
public List<Role> getAllRoles()
{
return super.getHibernateTemplate().find("from Role");
} }

定义DeptDaoImpl

 package org.guangsoft.dao.impl;

 import java.util.List;

 import org.guangsoft.dao.DeptDao;
import org.guangsoft.pojo.Dept;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository; /**
* 建立dao接口实现类
* extends HibernateDaoSupport
* 完成dao中获得session
* @author guanghe
*
*/
@Repository
public class DeptDaoImpl extends HibernateDaoSupport implements DeptDao
{
/**
* 给父类注入sessionFactory通过自动装配
* @param sessionFactory
*/
@Autowired
public void setSessionFactoryAutoWire(SessionFactory sessionFactory)
{
super.setSessionFactory(sessionFactory);
} /**
* 查询部门列表
*/
@Override
public List<Dept> getAllDepts()
{
return super.getHibernateTemplate().find("from Dept");
} }

1.5建立Servie接口

 package org.guangsoft.service;

 import java.util.List;

 import org.guangsoft.vo.UserVo;

 /**
* 部门的业务接口
* @author guanghe
*/
public interface UserService
{
//封装部门集合和角色的集合
public UserVo loadDeptRoleService();
//添加用户信息
public void saveUserService(UserVo userVo);
//加载用户列表
public List<UserVo> loadUserListService();
//删除用户
public void deleteUserService(UserVo userVo);
//修改用户
public void updateUserService(UserVo userVo);
//根据id获得用户
public UserVo getUserByIdService(UserVo userVo);
}

1.6建立service接口实现类

 package org.guangsoft.service.impl;

 import java.util.ArrayList;
import java.util.List;
import java.util.Set; import org.apache.commons.beanutils.BeanUtils;
import org.guangsoft.dao.DeptDao;
import org.guangsoft.dao.RoleDao;
import org.guangsoft.dao.UserDao;
import org.guangsoft.pojo.Dept;
import org.guangsoft.pojo.Role;
import org.guangsoft.pojo.User;
import org.guangsoft.service.UserService;
import org.guangsoft.vo.UserVo;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;
/**
* 部门业务接口实现类
* @author guanghe
*
*/
@Service
public class UserServiceImpl implements UserService
{
//声明dao对象
@Autowired
private UserDao userDao;
@Autowired
private DeptDao deptDao;
@Autowired
private RoleDao roleDao; @Override
public UserVo loadDeptRoleService()
{
List<Dept> deptList = deptDao.getAllDepts();
List<Role> roleList = roleDao.getAllRoles();
UserVo userVo = new UserVo();
userVo.setDeptList(deptList);
userVo.setRoleList(roleList);
return userVo;
} @Override
public void saveUserService(UserVo userVo)
{
//将userVo转化为pojo对象
User user = new User();
try
{
org.springframework.beans.BeanUtils.copyProperties(userVo, user);
}
catch (Exception e)
{
e.printStackTrace();
}
userDao.saveUser(user);
//通过user建立和部门关系
Integer did = userVo.getDid();
if(!"".equals(did) && did != null)
{
Dept dept = new Dept();
dept.setDid(did);
user.setDept(dept);
}
//通过user建立和角色的关系
Integer rids[] = userVo.getRids();
if(rids != null)
{
for(Integer rid : rids)
{
Role role = new Role();
role.setRid(rid);
user.getRoles().add(role);
}
}
} @Override
public List<UserVo> loadUserListService()
{
List<User> userList = userDao.getAllUsers();
//创建UserVoList集合
List<UserVo> userVoList = new ArrayList<UserVo>();
//将数据库查询到的结果封装为需要给用户显示的数据模型
for(User user : userList)
{
//封装用户的角色集合
Set<Role> roleSet = user.getRoles();
StringBuffer rnameBuffer = new StringBuffer();
for(Role role : roleSet)
{
rnameBuffer.append(role.getRname());
rnameBuffer.append(',');
}
String rname = rnameBuffer.toString();
if(!"".equals(rname))
{
rname = rname.substring(0,rname.lastIndexOf(','));
}
UserVo userVo = new UserVo();
try
{
org.springframework.beans.BeanUtils.copyProperties(user, userVo);
}
catch (Exception e)
{
e.printStackTrace();
}
userVo.setRname(rname);
userVoList.add(userVo);
}
return userVoList;
} @Override
public void deleteUserService(UserVo userVo)
{
//将userVo转化为pojo对象
User user = new User();
try
{
org.springframework.beans.BeanUtils.copyProperties(userVo, user);
}
catch (Exception e)
{
e.printStackTrace();
}
user = userDao.getUserById(user);
user.setDept(null);
user.setRoles(null);
userDao.deleteUser(user);
} @Override
public void updateUserService(UserVo userVo)
{
//将userVo转化为pojo对象
User user = new User();
try
{
org.springframework.beans.BeanUtils.copyProperties(userVo, user);
}
catch (Exception e)
{
e.printStackTrace();
}
userDao.updateUser(user);
//通过user建立和部门关系
Integer did = userVo.getDid();
if(!"".equals(did) && did != null)
{
Dept dept = new Dept();
dept.setDid(did);
user.setDept(dept);
}
//通过user建立和角色的关系
Integer rids[] = userVo.getRids();
if(rids != null)
{
for(Integer rid : rids)
{
Role role = new Role();
role.setRid(rid);
user.getRoles().add(role);
}
}
} @Override
public UserVo getUserByIdService(UserVo userVo)
{
User user = new User();
user.setUid(userVo.getUid());
user = userDao.getUserById(user);
org.springframework.beans.BeanUtils.copyProperties(user, userVo);
return userVo;
}
}

1.7建立UsersAction

 package org.guangsoft.action;
import java.util.List; import org.guangsoft.service.UserService;
import org.guangsoft.vo.UserVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller; import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ModelDriven; @Controller
@Scope("prototype")
public class UserAction implements ModelDriven<UserVo>
{
//自动装配service
@Autowired
private UserService userService;
//创建页面对象
private UserVo userVo = new UserVo(); @Override
public UserVo getModel()
{
return userVo;
}
public UserVo getUserVo()
{
return userVo;
}
public void setUserVo(UserVo userVo)
{
this.userVo = userVo;
}
public UserService getUserService()
{
return userService;
}
public void setUserService(UserService userService)
{
this.userService = userService;
} //加载添加用户页面
public String loadSaveUi()
{
UserVo userVoLoad = userService.loadDeptRoleService();
userVo.setDeptList(userVoLoad.getDeptList());
userVo.setRoleList(userVoLoad.getRoleList());
return ActionConstants.TO_SAVE_UI;
} //添加用户
public String addUser()
{
userService.saveUserService(userVo);
return ActionConstants.TO_LIST_ACTION;
} //加载修改用户页面
public String loadUpdateUi()
{
userVo = userService.getUserByIdService(userVo);
loadSaveUi();
return ActionConstants.TO_UPDATE_UI;
} //修改用户
public String updateUser()
{
userService.updateUserService(userVo);
return ActionConstants.TO_LIST_ACTION;
} //加载用户列表
public String loadListUi()
{
//获得用户集合
List<UserVo> userVoList = userService.loadUserListService();
ActionContext.getContext().put("userVoList", userVoList);
return ActionConstants.TO_LIST_UI;
} //删除用户
public String deleteUser()
{
userService.deleteUserService(userVo);
return ActionConstants.TO_LIST_ACTION;
} }

1.8配置Action

 <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="user" namespace="/" extends="struts-default">
<!-- action在spring容器中对应的id -->
<action name="userAction_*" class="userAction" method="{1}">
<result name="TO_SAVE_UI">/WEB-INF/jsp/saveUser.jsp</result>
<result name="TO_UPDATE_UI">/WEB-INF/jsp/updateUser.jsp</result>
<result name="TO_LIST_UI">/WEB-INF/jsp/userList.jsp</result>
<result name="TO_LIST_ACTION" type="redirectAction">userAction_loadListUi</result>
</action>
</package>
</struts>

1.9建立测试文件

TestUserDao.java

 package org.guangsoft.test;

 import java.util.List;

 import org.guangsoft.dao.UserDao;
import org.guangsoft.pojo.User;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class TestUserDao
{
@Test
public void testSaveUser()
{
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
UserDao userDao = (UserDao) ac.getBean("userDaoImpl");
User user = new User();
user.setUsername("testUserDao01");;
userDao.saveUser(user);
} @Test
public void testGetAllUsers()
{
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
UserDao userDao = (UserDao) ac.getBean("userDaoImpl");
List<User> userList = userDao.getAllUsers();
System.out.println(userList);
} @Test
public void testdeleteUser()
{
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
UserDao userDao = (UserDao) ac.getBean("userDaoImpl");
User user = new User();
user.setUid(45);
user = userDao.getUserById(user);
userDao.deleteUser(user);
} @Test
public void testUpdateUser()
{
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
UserDao userDao = (UserDao) ac.getBean("userDaoImpl");
User user = new User();
user.setUid(46);
user.setUsername("sfdsfsdfdsfds");
user.setDept(null);
userDao.updateUser(user);
}
}

TestUserService.java

 package org.guangsoft.test;

 import java.util.List;

 import org.guangsoft.service.UserService;
import org.guangsoft.vo.UserVo;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class TestUserService
{
@Test
public void testLoadSaveUiService()
{
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
UserService userService = (UserService) ac.getBean("userServiceImpl");
UserVo userVo = userService.loadDeptRoleService();
System.out.println(userVo.getDeptList());
System.out.println(userVo.getRoleList());
} @Test
public void testSaveUserService()
{
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
UserService userService = (UserService) ac.getBean("userServiceImpl");
UserVo userVo = new UserVo();
Integer rids[] = {1,2,3};
userVo.setRids(rids);
userVo.setDid(1);
userVo.setUsername("test02");
userService.saveUserService(userVo);
} @Test
public void testLoadListUiService()
{
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
UserService userService = (UserService) ac.getBean("userServiceImpl");
List<UserVo> userVoList = userService.loadUserListService();
System.out.println(userVoList.get(0).getUsername());
} @Test
public void testDeleteUserService()
{
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
UserService userService = (UserService) ac.getBean("userServiceImpl");
UserVo userVo = new UserVo();
userVo.setUid(47);
userService.deleteUserService(userVo);
} @Test
public void testUpdateUserService()
{
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
UserService userService = (UserService) ac.getBean("userServiceImpl");
UserVo userVo = new UserVo();
Integer rids[] = {1,2,3};
userVo.setRids(rids);
userVo.setDid(1);
userVo.setUsername("test02");
userVo.setUid(46);
userService.updateUserService(userVo);
} @Test
public void testGetUserByIdService()
{
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
UserService userService = (UserService) ac.getBean("userServiceImpl");
UserVo userVo = new UserVo();
userVo.setUid(49);
userVo = userService.getUserByIdService(userVo);
System.out.println(userVo.getUsername());
}
}

1.10建立辅助文件

UsersVo.java(封装客户端请求的数据,需要响应到客户端的数据)

 package org.guangsoft.vo;

 import java.util.Arrays;
import java.util.List; import org.guangsoft.pojo.Dept;
import org.guangsoft.pojo.Role;
import org.guangsoft.pojo.User; /**
* 定义User的vo类
* 封装需要给哭护短响应的数据
* 封装接受请求的数据
* @author guanghe
*/
public class UserVo extends User
{
//在添加用户的时候需要加载部门的集合
private List<Dept> deptList;
//封装角色的集合
private List<Role> roleList;
//获得角色的id
private Integer rids[];
//获得部门id
private Integer did;
//保存用户角色的名字,展示使用
private String rname; public List<Dept> getDeptList()
{
return deptList;
}
public void setDeptList(List<Dept> deptList)
{
this.deptList = deptList;
}
public Integer[] getRids()
{
return rids;
}
public void setRids(Integer[] rids)
{
this.rids = rids;
}
public List<Role> getRoleList()
{
return roleList;
}
public void setRoleList(List<Role> roleList)
{
this.roleList = roleList;
}
public String getRname()
{
return rname;
}
public void setRname(String rname)
{
this.rname = rname;
}
public Integer getDid()
{
return did;
}
public void setDid(Integer did)
{
this.did = did;
} }

ActionContants(常量池,封装了跳转的常用字符串)

 package org.guangsoft.action;

 public interface ActionConstants
{
String TO_SAVE_UI = "TO_SAVE_UI";
String TO_UPDATE_UI = "TO_UPDATE_UI";
String TO_LIST_UI = "TO_LIST_UI";
String TO_LIST_ACTION = "TO_LIST_ACTION";
}

Commons.jsp(将公共的资源文件进行统一管理)

 <link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/css/blue/pageCommon.css" />
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>

1.11建立页面

加载saveUser.jsp,主要显示所有的部门和角色

 <%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML>
<html>
<head>
<title>添加用户</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<base href="<%=basePath%>">
<%@ include file="commons.jsp"%>
<script src="js/user.js"></script>
</head>
<body>
<div id="Title_bar">
<div id="Title_bar_Head">
<div id="Title_Head"></div>
<div id="Title">
<img border="0" width="13" height="13" src="${pageContext.request.contextPath}/css/images/title_arrow.gif"/> 用户信息
</div>
<div id="Title_End"></div>
</div>
</div>
<div id=MainArea>
<s:form action="userAction_addUser.action" id="addUserForm" theme="simple" method="post">
<div class="ItemBlock_Title1">
<img border="0" width="4" height="7" src="${pageContext.request.contextPath}/css/blue/images/item_point.gif" /> 用户信息
</div>
<div class="ItemBlockBorder">
<div class="ItemBlock">
<table cellpadding="0" cellspacing="0" class="mainForm">
<tr>
<td width="100">所属部门</td>
<td>
<s:select list="deptList" listKey="did" listValue="dname"
name="did" cssClass="SelectStyle" />
</td>
</tr>
<tr><td>登录名</td>
<td>
<s:textfield name="username" cssClass="InputStyle" />*(登录名要唯一)
</td>
</tr>
<tr>
<td>性别</td>
<td>
<s:radio list="#{'男':'男','女':'女'}" name="sex"></s:radio>
</td>
</tr>
<tr>
<td>联系电话</td>
<td>
<s:textfield name="phone" cssClass="InputStyle"/>
</td>
</tr>
<tr>
<td>E-mail</td>
<td>
<s:textfield name="email" cssClass="InputStyle"></s:textfield>
</td>
</tr>
</table>
</div>
</div> <div class="ItemBlock_Title1">
<img border="0" width="4" height="7" src="${pageContext.request.contextPath}/css/blue/images/item_point.gif" /> 岗位设置
</div> <!-- 表单内容显示 -->
<div class="ItemBlockBorder">
<div class="ItemBlock">
<table cellpadding="0" cellspacing="0" class="mainForm">
<tr>
<td width="100">岗位</td>
<td>
<s:select list="roleList" listKey="rid" listValue="rname"
name="rids" cssClass="SelectStyle" multiple="true" />
按住Ctrl键可以多选或取消选择
</td>
</tr>
</table>
</div>
</div> <!-- 表单操作 -->
<div id="InputDetailBar">
<input type="image" onclick="addUser();" src="${pageContext.request.contextPath}/css/images/save.png"/>
<a href="javascript:history.go(-1);"><img src="${pageContext.request.contextPath}/css/images/goBack.png"/></a>
</div>
</s:form>
</div> <div class="Description">
说明:<br />
1,用户的登录名要唯一,在填写时要同时检测是否可用。<br />
2,新建用户后,密码被初始化为"1234"。<br />
3,密码在数据库中存储的是MD5摘要(不是存储明文密码)。<br />
4,用户登录系统后可以使用“个人设置→修改密码”功能修改密码。<br />
5,新建用户后,会自动指定默认的头像。用户可以使用“个人设置→个人信息”功能修改自已的头像<br />
6,修改用户信息时,登录名不可修改。
</div>
</body>
</html>

加载userList.jsp

 <%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort() + path + "/";
%> <!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">
<title>用户列表</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%@ include file="commons.jsp"%>
</head> <body>
<div id="Title_bar">
<div id="Title_bar_Head">
<div id="Title_Head"></div>
<div id="Title">
<img border="0" width="13" height="13"
src="${pageContext.request.contextPath}/css/images/title_arrow.gif" /> 用户管理
</div>
<div id="Title_End"></div>
</div>
</div>
<div id="MainArea">
<table cellspacing="0" cellpadding="0" class="TableStyle">
<thead>
<tr align=center valign=middle id=TableTitle>
<td width="100">用户名</td>
<td width="100">电话</td>
<td width="100">所属部门</td>
<td>角色</td>
<td>相关操作</td>
</tr>
</thead>
<tbody id="TableData" class="dataContainer" datakey="userList">
<s:iterator value="userVoList" id="userVo">
<tr class="TableDetail1 template">
<td><s:property value="#userVo.username" />&nbsp;</td>
<td><s:property value="#userVo.phone" />&nbsp;</td>
<td><s:property value="#userVo.dept.dname" />&nbsp;</td>
<td><s:property value="#userVo.rname" />&nbsp;</td>
<td>
<s:a href="userAction_loadUpdateUi.action?uid=%{#userVo.uid}">修改</s:a>&nbsp;&nbsp;
<s:a href="userAction_deleteUser.action?uid=%{#userVo.uid}" >删除</s:a>&nbsp;&nbsp;
</td>
</tr>
</s:iterator>
</tbody>
</table>
<div id="TableTail">
<div id="TableTail_inside">
<a href="userAction_loadSaveUi.action"><img src="${pageContext.request.contextPath}/css/images/createNew.png" /></a>
</div>
</div>
</div>
</body>
</html>
上一篇:UVA-11214 IDA*


下一篇:五道java小题,补更四道java小题