MySQL语句(DCL)
1、创建用户
语法:
CREATE USER 用户名@地址 IDENTIFIED BY '密码';
CREATE USER user1@localhost IDENTIFIED BY '123';
CREATE USER user2@'%' IDENTIFIED BY '123';
*表示user2用户可以在任何主机上访问本地的数据库
2 给用户授权
语法:
GRANT 权限1, … , 权限n ON 数据库.* TO 用户名@IP
GRANT CREATE,ALTER,DROP,INSERT,UPDATE,DELETE,SELECT ON mydb1.* TO user1@localhost;
GRANT ALL ON mydb1.* TO user2@’%’;
3 撤销授权
语法:
REVOKE权限1, … , 权限n ON 数据库.* FORM 用户名
REVOKE CREATE,ALTER,DROP ON mydb1.* FROM user1@localhost;
4 查看用户权限
语法:
SHOW GRANTS FOR 用户名
SHOW GRANTS FOR user1@localhost;
5 删除用户
语法:
DROP USER 用户名
DROP USER user1@localhost;
6 修改用户密码
语法:
Use mysql;
UPDATE USER SET PASSWORD=PASSWORD(‘密码’) WHERE User=’用户名’;
FLUSH PRIVILEGES;
UPDATE USER SET PASSWORD=PASSWORD('1234') WHERE User='user2';
FLUSH PRIVILEGES;
一、 项目本地导入
MyEclipse 新建 web project , 覆盖对应 src 和 WebRoot
Eclipse 新建 Dynamic web project , 覆盖src , 将WebRoot 中内容复制 WebContent 目录
JavaEE 企业级应用软件,布局经常采用 Frameset , 左侧菜单树使用Dztree js组件制作的
目标功能 :
1、 登陆
2、 添加用户 (简历上传)
3、 组合条件 员工信息列表查询
4、 员工信息详情查看(简历下载)
5、 员工信息删除
6、 员工信息编辑
7. 异常处理
8. 登录校验
--------------------------------------------------------------
二、 数据库设计
#新建数据库
create database struts2exec;
#创建用户
create user struts2@localhost identified by 'struts2';
#授权
grant all on struts2exec.* to struts2@localhost;
***** Oracle和MySQL 作为应用数据库区别
mysql存在数据库概念,在企业开发中,针对一个项目创建一个单独数据库,创建单独用户, 为用户授予数据库权限 ,oracle 一个数据库就是一个服务,在这个库中可以存在很多用户,每个用户有单独表空间 ,针对一个项目,只需要创建一个用户
#用户表
CREATE TABLE S_User(
userID INT NOT NULL AUTO_INCREMENT, #主键ID
userName VARCHAR(50) NULL, #用户姓名
logonName VARCHAR(50) NULL, #登录名
logonPwd VARCHAR(50) NULL, #密码#
sex VARCHAR(10) NULL, #性别(例如:男,女)
birthday VARCHAR(50) NULL, #出生日期
education VARCHAR(20) NULL, #学历(例如:研究生、本科、专科、高中)
telephone VARCHAR(50) NULL, #电话
interest VARCHAR(20) NULL, #兴趣爱好(例如:体育、旅游、逛街)
path VARCHAR(500) NULL, #上传路径(path路径)
filename VARCHAR(100) NULL, #上传文件名称(文件名)
remark VARCHAR(500) NULL, #备注
PRIMARY KEY (userID)
);
#初始化数据:默认用户名和密码是admin
INSERT INTO s_user (userID,userName,logonName,logonPwd) VALUES (1,'超级管理员','admin','admin');
---------------------------------------------------------------------------------------
三、 搭建开发环境
struts2 + javabean + DAO + C3P0 + DBUtils + MySQL
导入jar包 和 配置文件
创建包结构
cn.itcast.user.domain
cn.itcast.user.dao
cn.itcast.user.service
cn.itcast.user.web.action
cn.itcast.user.utils
=======================================================================================
功能实现:
1.登录操作
1.使用struts2提供的表单标签来改造页面。
WebRoot/login/login.jsp
<form>-------------------<s:form>
<input type="text">------<s:textfield>
<input type="password">---<s:password>
<input type="submit">-----<s:submit>
<input type="reset">------<s:reset>
在struts2的doc下有一个tag-reference.html.
1.改造form
<s:form id="loginAction_home" name="form1" action="user_login" namespace="/" target="_parent" method="post">
2.改造登录名
<s:textfield name="logonName" value="" id="logonName" cssClass="text" cssStyle="width: 160px;"/>
3.改造登录密码
<s:password name="logonPwd" id="logonPwd" cssClass="text" cssStyle="width: 160px;"/>
密码框默认不回显示.需要设置属性showPassword="true"
4.<s:submit name="submit" value="登录" cssClass="buttoninput"/>
5.<s:reset name="reset" value="取消" cssClass="buttoninput"/>
注意:struts2中的表单标签,有默认的主题xhtml.如果不想要添加任何修饰,只需要将主题修改为simple.
问题:怎样设置主题
1.全局
在struts.xml文件中配置一个常量
<constant name="struts.ui.theme" value="simple"></constant>
2.局部
针对于某一个form.
<s:form theme="simple">
3.局部
可以给任意的表单组件去指定theme属性值。
2.需要使用xml配置方式对数据进行校验。
用户名 非空,3-12位
密码 非空
1.在UserAction所在包下创建一个UserAction-validation.xml
2.在xml文件中添加dtd约束
<!DOCTYPE validators PUBLIC
"-//Apache Struts//XWork Validator 1.0.3//EN"
"http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd">
3.对属性进行校验
<field name="logonName">
<field-validator type="requiredstring">
<message>用户名不能为空</message>
</field-validator>
<field-validator type="stringlength">
<param name="maxLength">12</param>
<param name="minLength">3</param>
<message>用户名长度必须在${minLength}到${maxLength}之间</message>
</field-validator>
</field>
<field name="logonPwd">
<field-validator type="requiredstring">
<message>密码不能为空</message>
</field-validator>
</field>
在页面上通过<s:fielderror>
3.登录成功,将用户存储到session,在页面上显示用户。
top.jsp ${user.userName } 显示当前登陆用户
----------------------------------------------------------------------------------------
2.查询功能--查询全部
登录成功后,跳转到home.jsp页面。home.jsp页面使用了frameset布局。
它的左边(left.jsp)页面使用了dtree,来展示。有一个连接用户管理,
当点击它时,打开了list.jsp页面。
问题:点击用户管理,应该直接打开list.jsp页面?
当点击用户管理时,应该访问UserAction中的list方法,查询出所有的List<User>
在跳转到list.jsp页面,展示出所有用户。
实现:
1.修改left.jsp页面上的用户管理的连接。
原来:d.add(3,2,'用户管理','${pageContext.request.contextPath}/user/list.jsp','','mainFrame');
修改后
d.add(3,2,'用户管理','${pageContext.request.contextPath}/user_list','','mainFrame');
2.在list方法中调用service,dao完成查询操作
得到一个List<User> users;
我们将List<User> users声明成成员变量,提供get/set方法,
这样,集合就会自动的压入到valueStack中.
问题:
1.返回SUCCESS问题 因为我们的配置是使用了通配符,一个配置对应多个请求。
这时,有可能有多种情况都返回SUCCESS,所以我们修改.
登录成功返回 login_success 查询所有成功 list_success.
2.关于查询操作时,校验的配置文件会执行。
原因:我们之前配置文件名称叫 UserAction-validation.xml,它会对UserAction下所有方法校验。
解决:将其修改为 UserAction-user_login-validation.xml 这就只会对user_login进行校验。
3.查询成功跳转到了 list.jsp,在页面上展示信息.
------------------------------------------------------------------------------------------------------
3.添加员工
1.对add.jsp页面上html标签修改----struts2的表单标签
1.性别
原标签
<input type="radio" name="sex" id="sex男" value="男"/><label for="sex男">男</label>
<input type="radio" name="sex" id="sex女" value="女"/><label for="sex女">女</label>
struts2标签:
<s:radio list="{'男','女'}" name="sex" id="sex" value="%{'男'}"/>
2.学历
原标签:
<select name="education" id="education">
<option value=""
selected="selected"
>--选择学历--</option>
<option value="博士">博士</option>
<option value="硕士">硕士</option>
<option value="研究生">研究生</option>
<option value="本科">本科</option>
<option value="专科">专科</option>
<option value="高中">高中</option>
</select>
struts2标签
<s:select list="{'博士','硕士','研究生','本科','专科','高中'}" name="education" id="education" headerKey="" headerValue="--选择学历--"></s:select>
3.兴趣爱好
<s:checkboxlist list="{'看电影','旅游','健身','购物','睡觉'}" name="interest"/>
4.上传
<s:file name="upload" size="30" value="" id="userAction_save_do_upload"/>
5.文本域
<s:textarea name="remark" cols="30" rows="3" id="userAction_save_do_remark" cssStyle="WIDTH: 96%"/>
2.添加数据的校验
在UserAction类所在包下创建一个 UserAction-user_add-validation.xml
3.完成添加操作(上传)
问题:怎样将要添加的信息在action中获取到?
在UserAction类中有一个 private User user=new User();
我们又声明了
private File upload;
private String uploadContentType;
private String uploadFileName;
添加的用户信息,除了上传文件的信息,其它的都封装到了user对象中。
而上传文件信息在三个属性上封装。
对于我们添加用户还需要有下列信息:
userID----->自动增长
path------->人为指定。
简历不允许被浏览器端直接访问。
d:/upload下.
上传简历,保存时的重名问题.
d:/upload/随机名.
filename=真实名
对于我们上面操作,因为多个action在同一个配置中(使用了通配符).
多个请求操作时,可能都需要跳转到input视图。但是它们跳转的页面
不一样,怎样处理?
可以 通过 @InputConfig注解,改为校验失败后 跳转视图
------------------------------------------------------------------------------------
4.条件查询
1.在list.jsp页面修改查询组件
是否上传简历
<s:select list="#{'1':'有','2':'无'}" name="isUpload" id="isUpload" headerKey="0" headerValue="--请选择--"></s:select>
2.添加校验
3.完成条件查询操作
问题:是否上传简历,怎样在action中获取?
需要在User中添加一个属性 String isUpload
在dao中怎样根据条件查询?
1.sql语句生成
2.参数怎样传递?
创建一个List<Object>,在每一次判断时,直接将参数添加到集合中,
最后将集合转换成Object[],做为参数传递到query方法中。
String sql = "select * from s_user where 1=1 ";
List<Object> params=new ArrayList<Object>();
String username = user.getUserName();
if (username != null && username.trim().length() > 0) {
sql += " and userName like ?";
params.add("%"+username+"%");
}
String sex = user.getSex();
if (sex != null && sex.trim().length() > 0) {
sql += " and sex=?";
params.add(sex);
}
String education = user.getEducation();
if (education != null && education.trim().length() > 0) {
sql += " and education=?";
params.add(education);
}
String isupload = user.getIsUpload();
if ("1".equals(isupload)) {
sql += " and filename is not null";
} else if ("2".equals(isupload)) {
sql += " and filename is null";
}
QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
return runner.query(sql, new BeanListHandler<User>(User.class),params.toArray());
--------------------------------------------------------------------------------------------------
5.员工删除
在list.jsp页面上有删除链接,我们只需要将当前用户的id传递到服务器端
在服务器端根据id删除用户信息。删除完成,在查询一次。
1.修改list.jsp页面上删除连接
原标签:
<a href="${pageContext.request.contextPath}/user/list.jsp?userID=15">
<img src="${pageContext.request.contextPath}/images/i_del.gif" width="16" height="16" border="0" style="CURSOR: hand">
</a>
使用struts2标签修改
第一种方式
<s:a href="路径">
第二种方式
<s:a action="" namespace="">
<s:param name="" value="">
</s:a>
第三种方式:
<s:url>标签来定义一个路径
<s:a href="url">来导入url值。
<s:url namespace="/" action="user_del" var="delUrl">
<s:param name="id" value="%{#u.userID}"/>
</s:url>
<s:a href="%{#delUrl}">
<img src="${pageContext.request.contextPath}/images/i_del.gif" width="16" height="16" border="0" style="CURSOR: hand">
</s:a>
2.完成删除操作
问题:如果用户有简历,删除用户时,也要将简历删除。
1.先查询出用户。
2.判断user.getPath()!=null
new File(user.getPath()).delete();
---------------------------------------------------------------------------------------
6.员工详细信息查看
在list.jsp页面,有查看客户详细信息连接。
<s:url namespace="/" action="user_findById" var="findByIdUrl">
<s:param name="userID" value="%{#u.userID}"/>
</s:url>
<s:a href="%{#findByIdUrl}">
<img src="${pageContext.request.contextPath}/images/button_view.gif" border="0" style="CURSOR: hand">
</s:a>
查询出用户信息(user),需要在view.jsp页面展示
在页面上展示时,我们不能使用valueStack栈顶的user对象,而要
使用压入的action的getModel方法,重新得到user对象去获取信息。
-----------------------------------------------------------------------------------------
7.员工简历下载(作业)
在view.jsp页面上展示的员工信息包含了简历,它是一个连接,点击它,实现员工简历下载。
在<result name="download_success" type="stream">
<param name="contentType">${contentType}</param>
<param name="contentDisposition">attachment;filename=${downloadFilename}</param>
<param name="inputStream">${inputStream}</param>
</result>
-----------------------------------------------------------------------------------------
8.员工信息修改
1.查询
<a href="${pageContext.request.contextPath}/user/edit.jsp?userID=15">
<img src="${pageContext.request.contextPath}/images/i_edit.gif" border="0" style="CURSOR: hand">
</a>
<s:url namespace="/" action="user_updateForFind" var="editUrl">
<s:param name="userID" value="%{#u.userID}"/>
</s:url>
<s:a href="%{#editUrl}">
<img src="${pageContext.request.contextPath}/images/i_edit.gif" border="0" style="CURSOR: hand">
</s:a>
查询出user对象,跳转到edit.jsp页面,展示用户信息。
2.修改
修改就是一个上传操作:
问题:在修改时,关于用户简历的处理?
1.原来没有 修改也没有。---不管
2.原来没有 修改有了 ----处理
3.原来有 修改没有了 -----不管
4.原来有 修改也有. -----处理(将旧的删除)
修改前必须先查询出用户。
==================================================================================
9.登陆校验拦截器
功能:用户只有登录成功后,才可以进行操作.
做一个Interceptor.判断用户是否登录了。(登录标志session中有user)
自定义Interceptor步骤:
1.创建一个类,实现Interceptor接口
2.重写方法完成功能
3.在struts.xml文件注册
4.在action中引入
=================================================================================
10.struts2 提供的异常处理
对于action中的操作,出现问题,直接抛出自定义异常。
在struts.xml文件中
<global-exception-mappings>
<exception-mapping result="login"
exception="cn.itcast.user.exception.FindByIdException"></exception-mapping>
</global-exception-mappings>
这就可以让特定的异常,跳转到自定的页面。
原理:
struts2,默认加载的18个拦截器的第一个是exception这个拦截器,它没有做任何操作,
直接放行,,只是它将 invocation.invoke()操作使用try-catch进行了处理。
其它的拦截器,或是action只要向外抛出异常,exception拦截器就会将其捕获。
UserDao
package cn.itcast.user.dao;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import cn.itcast.user.domain.User;
import cn.itcast.user.utils.DataSourceUtils;
public class UserDao {
// 登录
public User findUserByNameAndPwd(String logonName, String logonPwd)
throws SQLException {
String sql = "select * from s_user where logonName=? and logonPwd=?";
QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
return runner.query(sql, new BeanHandler<User>(User.class), logonName,
logonPwd);
}
// 查询全部
public List<User> findAll() throws SQLException {
String sql = "select * from s_user";
QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
return runner.query(sql, new BeanListHandler<User>(User.class));
}
// 添加操作
public void addUser(User user) throws SQLException {
String sql = "insert into s_user values(null,?,?,?,?,?,?,?,?,?,?,?)";
QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
runner.update(sql, user.getUserName(), user.getLogonName(),
user.getLogonPwd(), user.getSex(), user.getBirthday(),
user.getEducation(), user.getTelephone(), user.getInterest(),
user.getPath(), user.getFilename(), user.getRemark());
}
// 条件查询
public List<User> findBySelect(User user) throws SQLException {
String sql = "select * from s_user where 1=1 ";
List<Object> params = new ArrayList<Object>();
String username = user.getUserName();
if (username != null && username.trim().length() > 0) {
sql += " and userName like ?";
params.add("%" + username + "%");
}
String sex = user.getSex();
if (sex != null && sex.trim().length() > 0) {
sql += " and sex=?";
params.add(sex);
}
String education = user.getEducation();
if (education != null && education.trim().length() > 0) {
sql += " and education=?";
params.add(education);
}
String isupload = user.getIsUpload();
if ("1".equals(isupload)) {
sql += " and filename is not null";
} else if ("2".equals(isupload)) {
sql += " and filename is null";
}
QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
return runner.query(sql, new BeanListHandler<User>(User.class),
params.toArray());
}
// 根据id删除
public void delById(int userID) throws SQLException {
String sql = "delete from s_user where userID=?";
QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
runner.update(sql, userID);
}
// 根据id查询
public User findById(int userID) throws SQLException {
String sql = "select * from s_users where userID=?";
QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
return runner.query(sql, new BeanHandler<User>(User.class), userID);
}
}
User
package cn.itcast.user.domain;
import java.io.Serializable;
public class User implements Serializable {
private int userID;
private String userName;
private String logonName;
private String logonPwd;
private String sex;
private String birthday;
private String education;
private String telephone;
private String interest;
private String path;
private String filename;
private String remark;
private String isUpload;
public String getIsUpload() {
return isUpload;
}
public void setIsUpload(String isUpload) {
this.isUpload = isUpload;
}
public int getUserID() {
return userID;
}
public void setUserID(int userID) {
this.userID = userID;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getLogonName() {
return logonName;
}
public void setLogonName(String logonName) {
this.logonName = logonName;
}
public String getLogonPwd() {
return logonPwd;
}
public void setLogonPwd(String logonPwd) {
this.logonPwd = logonPwd;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public String getEducation() {
return education;
}
public void setEducation(String education) {
this.education = education;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
public String getInterest() {
return interest;
}
public void setInterest(String interest) {
this.interest = interest;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
this.filename = filename;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
}
FindByIdException
package cn.itcast.user.exception;
public class FindByIdException extends Exception {
public FindByIdException() {
super();
// TODO Auto-generated constructor stub
}
public FindByIdException(String message, Throwable cause,
boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
// TODO Auto-generated constructor stub
}
public FindByIdException(String message, Throwable cause) {
super(message, cause);
// TODO Auto-generated constructor stub
}
public FindByIdException(String message) {
super(message);
// TODO Auto-generated constructor stub
}
public FindByIdException(Throwable cause) {
super(cause);
// TODO Auto-generated constructor stub
}
}
LoginException
package cn.itcast.user.exception;
public class LoginException extends Exception {
public LoginException() {
super();
// TODO Auto-generated constructor stub
}
public LoginException(String message, Throwable cause,
boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
// TODO Auto-generated constructor stub
}
public LoginException(String message, Throwable cause) {
super(message, cause);
// TODO Auto-generated constructor stub
}
public LoginException(String message) {
super(message);
// TODO Auto-generated constructor stub
}
public LoginException(Throwable cause) {
super(cause);
// TODO Auto-generated constructor stub
}
}
UserService
package cn.itcast.user.service;
import java.sql.SQLException;
import java.util.List;
import cn.itcast.user.dao.UserDao;
import cn.itcast.user.domain.User;
public class UserService {
// 登录操作
public User login(String logonName, String logonPwd) throws SQLException {
return new UserDao().findUserByNameAndPwd(logonName, logonPwd);
}
// 查询所有
public List<User> findAll() throws SQLException {
return new UserDao().findAll();
}
//添加用户
public void addUser(User user) throws SQLException {
new UserDao().addUser(user);
}
//条件查询
public List<User> findBySelect(User user) throws SQLException {
return new UserDao().findBySelect(user);
}
//根据id删除
public void delById(int userID) throws SQLException {
new UserDao().delById(userID);
}
//根据id查询用户
public User findById(int userID) throws SQLException {
return new UserDao().findById(userID);
}
}
DataSourceUtils
package cn.itcast.user.utils;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
import com.mchange.v2.c3p0.ComboPooledDataSource;
public class DataSourceUtils {
private static DataSource dataSource = new ComboPooledDataSource();
public static DataSource getDataSource() {
return dataSource;
}
/**
* 当DBUtils需要手动控制事务时,调用该方法获得一个连接
*
* @return
* @throws SQLException
*/
public static Connection getConnection() throws SQLException {
return dataSource.getConnection();
}
}
FileUploadUtils
package cn.itcast.user.utils;
import java.util.UUID;
public class FileUploadUtils {
//得到随机名
public static String getUUIDFileName(String filename){
int index=filename.lastIndexOf(".");
return UUID.randomUUID()+filename.substring(index);
}
}
UserAction
package cn.itcast.user.web.action;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;
import cn.itcast.user.domain.User;
import cn.itcast.user.exception.FindByIdException;
import cn.itcast.user.service.UserService;
import cn.itcast.user.utils.FileUploadUtils;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.interceptor.annotations.InputConfig;
public class UserAction extends ActionSupport implements ModelDriven<User> {
private User user = new User();
private List<User> users;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public List<User> getUsers() {
return users;
}
public void setUsers(List<User> users) {
this.users = users;
}
public User getModel() {
return user;
}
// 上传文件信息
private File upload;
private String uploadContentType;
private String uploadFileName;
public File getUpload() {
return upload;
}
public void setUpload(File upload) {
this.upload = upload;
}
public String getUploadContentType() {
return uploadContentType;
}
public void setUploadContentType(String uploadContentType) {
this.uploadContentType = uploadContentType;
}
public String getUploadFileName() {
return uploadFileName;
}
public void setUploadFileName(String uploadFileName) {
this.uploadFileName = uploadFileName;
}
// 根据id查询
public String findById() throws FindByIdException {
UserService service = new UserService();
try {
user = service.findById(user.getUserID());
} catch (SQLException e) {
//e.printStackTrace();
throw new FindByIdException();
}
return "findById_success";
}
// 修改前的查询
public String updateForFind() {
UserService service = new UserService();
try {
user = service.findById(user.getUserID());
} catch (SQLException e) {
e.printStackTrace();
}
return "updateForFind_success";
}
// 根据id删除操作
public String del() {
UserService service = new UserService();
try {
// 先查询用户,判断是否有简历,如果有简历,将简历删除。
user = service.findById(user.getUserID());
String path = user.getPath();
if (path != null) {
// 有简历,将简历删除
new File(path).delete();
}
service.delById(user.getUserID());
} catch (SQLException e) {
e.printStackTrace();
}
return "del_success";
}
// 条件查询
public String listSelect() {
// 调用service中条件查询操作
UserService service = new UserService();
try {
users = service.findBySelect(user);
} catch (SQLException e) {
e.printStackTrace();
}
return "listSelect_success";
}
// 添加用户操作
@InputConfig(resultName = "add_input")
public String add() throws IOException {
// 1.完成上传
if (upload != null) {
String uuidname = FileUploadUtils.getUUIDFileName(uploadFileName);
File dest = new File("d:/upload", uuidname);
FileUtils.copyFile(upload, dest);
// 2.调用service,dao完成添加操作
user.setPath("d:/upload/" + uuidname);
user.setFilename(uploadFileName);
}
UserService service = new UserService();
try {
service.addUser(user);
} catch (SQLException e) {
e.printStackTrace();
this.addActionError("添加失败");
return "input";
}
return "add_success";
}
// 查询所有
public String list() {
UserService service = new UserService();
try {
users = service.findAll();
// 手动
// ValueStack vs=ActionContext.getContext().getValueStack();
// vs.set("users", users);
// 自动:将users声明成成员变量,提供get/set
} catch (SQLException e) {
e.printStackTrace();
}
return "list_success";
}
// 登录操作
@InputConfig(resultName = "login_input")
public String login() {
// 调用service中登录方法.
UserService service = new UserService();
try {
user = service.login(user.getLogonName(), user.getLogonPwd());
if (user == null) {
this.addActionError("用户名或密码错误");
return Action.LOGIN;
}
ServletActionContext.getRequest().getSession()
.setAttribute("user", user);
} catch (SQLException e) {
e.printStackTrace();
// throw new LoginException();
this.addActionError("登录失败");
return Action.LOGIN;
}
return "login_success";
}
}
UserAction-user_add-validation.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC
"-//Apache Struts//XWork Validator 1.0.3//EN"
"http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd">
<validators>
<field name="logonName">
<field-validator type="requiredstring">
<message>用户名不能为空</message>
</field-validator>
<field-validator type="stringlength">
<param name="maxLength">12</param>
<param name="minLength">3</param>
<message>用户名长度必须在${minLength}到${maxLength}之间</message>
</field-validator>
</field>
<field name="logonPwd">
<field-validator type="requiredstring">
<message>密码不能为空</message>
</field-validator>
</field>
</validators>
UserAction-user_login-validation.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC
"-//Apache Struts//XWork Validator 1.0.3//EN"
"http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd">
<validators>
<field name="logonName">
<field-validator type="requiredstring">
<message>用户名不能为空</message>
</field-validator>
<field-validator type="stringlength">
<param name="maxLength">12</param>
<param name="minLength">3</param>
<message>用户名长度必须在${minLength}到${maxLength}之间</message>
</field-validator>
</field>
<field name="logonPwd">
<field-validator type="requiredstring">
<message>密码不能为空</message>
</field-validator>
</field>
</validators>
LoginInterceptor
package cn.itcast.user.web.interceptor;
import org.apache.struts2.ServletActionContext;
import cn.itcast.user.domain.User;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.Interceptor;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
//public class LoginInterceptor implements Interceptor {
public class LoginInterceptor extends MethodFilterInterceptor {
@Override
protected String doIntercept(ActionInvocation invocation) throws Exception {
User user = (User) ServletActionContext.getRequest().getSession()
.getAttribute("user");
if (user == null) {
// 没有登录
ActionSupport action = (ActionSupport) invocation.getAction();
action.addActionError("用户未登录");
return Action.LOGIN;
} else {
// 登录了
return invocation.invoke();
}
}
//
// public String intercept(ActionInvocation invocation) throws Exception {
//
// User user = (User) ServletActionContext.getRequest().getSession()
// .getAttribute("user");
//
// if (user == null) {
// // 没有登录
// ActionSupport action = (ActionSupport) invocation.getAction();
//
// action.addActionError("用户未登录");
//
// return Action.LOGIN;
// } else {
// // 登录了
// return invocation.invoke();
// }
//
// }
}
c3p0-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config>
<default-config>
<property name="user">struts2</property>
<property name="password">struts2</property>
<property name="driverClass">com.mysql.jdbc.Driver</property>
<property name="jdbcUrl">jdbc:mysql:///struts2exec</property>
</default-config> <!-- This app is massive! -->
</c3p0-config>
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.ui.theme" value="simple"></constant>
<package name="default" namespace="/" extends="struts-default">
<interceptors>
<interceptor name="loginInterceptor"
class="cn.itcast.user.web.interceptor.LoginInterceptor">
<param name="excludeMethods">login</param>
</interceptor>
<interceptor-stack name="myStack">
<interceptor-ref name="loginInterceptor" />
<interceptor-ref name="defaultStack" />
</interceptor-stack>
</interceptors>
<global-results>
<result name="login">/login/login.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping result="login"
exception="cn.itcast.user.exception.FindByIdException"></exception-mapping>
</global-exception-mappings>
<action name="user_*" class="cn.itcast.user.web.action.UserAction"
method="{1}">
<result name="login_success">/login/home.jsp</result>
<result name="login_input">/login/login.jsp</result>
<result name="list_success">/user/list.jsp</result>
<result name="add_success" type="redirectAction">user_list</result>
<result name="add_input">/user/add.jsp</result>
<result name="listSelect_success">/user/list.jsp</result>
<result name="del_success" type="redirectAction">user_list</result>
<result name="findById_success">/user/view.jsp</result>
<result name="updateForFind_success">/user/edit.jsp</result>
<interceptor-ref name="myStack" />
</action>
</package>
</struts>
home.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
body
{
SCROLLBAR-ARROW-COLOR: #ffffff; SCROLLBAR-BASE-COLOR: #dee3f7;
}
</style>
</head>
<frameset rows="103,*,43" frameborder=0 border="0" framespacing="0">
<frame src="${pageContext.request.contextPath}/login/top.jsp" name="topFrame" scrolling="NO" noresize>
<frameset cols="159,*" frameborder="0" border="0" framespacing="0">
<frame src="${pageContext.request.contextPath}/login/left.jsp" name="leftFrame" noresize scrolling="YES">
<frame src="${pageContext.request.contextPath}/login/welcome.jsp" name="mainFrame">
</frameset>
<frame src="${pageContext.request.contextPath}/login/bottom.jsp" name="bottomFrame" scrolling="NO" noresize>
</frameset>
</html>
left.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>菜单</title>
<link href="${pageContext.request.contextPath}/css/left.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="12"></td>
</tr>
</table>
<table width="100%" border="0">
<tr>
<td>
<div class="dtree">
<a href="javascript: d.openAll();">展开所有</a> | <a href="javascript: d.closeAll();">关闭所有</a>
<link rel="StyleSheet" href="${pageContext.request.contextPath}/css/dtree.css" type="text/css" />
<script type="text/javascript" src="${pageContext.request.contextPath}/js/dtree.js"></script>
<script type="text/javascript">
<!--
d = new dTree('d');
d.add(0,-1,'系统菜单树');
d.add(2,0,'员工管理','${pageContext.request.contextPath}/login/welcome.jsp','','mainFrame');
//子目录添加
d.add(3,2,'用户管理','${pageContext.request.contextPath}/user_list','','mainFrame');
document.write(d);
//-->
</script>
</div> </td>
</tr>
</table>
</body>
</html>
login.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<script type="text/javascript">
function ini(){
document.form1.logonName.focus();
}
</script>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<link href="${pageContext.request.contextPath}/css/Style.css" rel="stylesheet" type="text/css">
</head>
<body οnlοad="ini()">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<table width="452" height="290" border="0" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#FFFFFF">
<table width="452" height="290" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="74">
<img src="${pageContext.request.contextPath}/images/logintitle.gif">
</td>
</tr>
<tr>
<td align="center" valign="bottom" background="${pageContext.request.contextPath}/images/loginbg.gif">
<s:form id="loginAction_home" name="form1" action="user_login" namespace="/" target="_top" method="post" theme="simple">
<table border="0" align="center" cellpadding="2" cellspacing="0">
<tr align="center">
<td height="30" colspan="2" style="border-bottom: 1px dotted #cccccc">
<strong style="font-size: 14px;">请登录</strong>
</td>
</tr>
<tr align="center">
<td height="30" colspan="2" style="border-bottom: 1px dotted #cccccc">
<s:actionerror/>
<s:fielderror/>
</td>
</tr>
<tr>
<td height="30" nowrap>
<font color="000F60"><strong>用户名:</strong> </font>
</td>
<td>
<s:textfield name="logonName" id="logonName" cssClass="text" cssStyle="width: 160px;"/>
</td>
</tr>
<tr>
<td height="30" nowrap>
<strong><font color="000F60">密码: </font> </strong>
</td>
<td>
<s:password name="logonPwd" id="logonPwd" showPassword="true" cssClass="text" cssStyle="width: 160px;"/>
</td>
</tr>
<tr>
<td height="30" nowrap colspan="2">
<strong><font color="red"></font> </strong>
</td>
</tr>
<tr>
<td height="30">
</td>
<td>
<s:submit name="submit" value="登录" cssClass="buttoninput"/>
<s:reset name="reset" value="取消" cssClass="buttoninput"/>
</td>
</tr>
</table>
</s:form>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="30" align="center">
</td>
</tr>
<tr>
<td height="23" align="center"></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
top.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
BODY {
MARGIN: 0px;
BACKGROUND-COLOR: #ffffff
}
BODY {
FONT-SIZE: 12px;
COLOR: #000000
}
TD {
FONT-SIZE: 12px;
COLOR: #000000
}
TH {
FONT-SIZE: 12px;
COLOR: #000000
}
</style>
<link href="${pageContext.request.contextPath}/css/Style.css" rel="stylesheet" type="text/css">
</HEAD>
<body>
<table width="100%" height="70%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<img width="100%" src="${pageContext.request.contextPath}/images/top_01.jpg">
</td>
<td width="100%" background="${pageContext.request.contextPath}/images/top_100.jpg">
</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="30" valign="bottom" background="${pageContext.request.contextPath}/images/mis_01.jpg">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="85%" align="left">
<font color="#000000"> <script language="JavaScript">
<!--
tmpDate = new Date();
date = tmpDate.getDate();
month= tmpDate.getMonth() + 1 ;
year= tmpDate.getYear();
document.write(year);
document.write("年");
document.write(month);
document.write("月");
document.write(date);
document.write("日 ");
myArray=new Array(6);
myArray[0]="星期日"
myArray[1]="星期一"
myArray[2]="星期二"
myArray[3]="星期三"
myArray[4]="星期四"
myArray[5]="星期五"
myArray[6]="星期六"
weekday=tmpDate.getDay();
if (weekday==0 | weekday==6)
{
document.write(myArray[weekday])
}
else
{document.write(myArray[weekday])
};
// -->
</script> </font>
</td>
<td width="15%">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="16"
background="${pageContext.request.contextPath}/images/mis_05b.jpg">
<img
src="${pageContext.request.contextPath}/images/mis_05a.jpg"
width="6" height="18">
</td>
<td width="155" valign="bottom"
background="${pageContext.request.contextPath}/images/mis_05b.jpg">
用户名:
<font color="blue">${user.userName}</font>
</td>
<td width="10" align="right"
background="${pageContext.request.contextPath}/images/mis_05b.jpg">
<img src="${pageContext.request.contextPath}/images/mis_05c.jpg" width="6" height="18">
</td>
</tr>
</table>
</td>
<td align="right" width="5%">
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</HTML>
welcome.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="${pageContext.request.contextPath}/css/Style.css" type="text/css" rel="stylesheet" />
<style type="text/css">
<!--
body {
background-color: #FFFFFF;
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
body,td,th {
color: #000000;
}
-->
</style>
<style>
BODY {SCROLLBAR-FACE-COLOR: #cccccc; SCROLLBAR-HIGHLIGHT-COLOR: #ffffFF; SCROLLBAR-SHADOW-COLOR: #ffffff; SCROLLBAR-3DLIGHT-COLOR: #cccccc; SCROLLBAR-ARROW-COLOR: #ffffff; SCROLLBAR-TRACK-COLOR: #ffffFF; SCROLLBAR-DARKSHADOW-COLOR: #cccccc; }
</style>
</head>
<body>
<form name="Form1" method="post" action="name.aspx" id="Form1">
<table width="100%" border="0" height="88" border="1" background="${pageContext.request.contextPath}/images/back1.JPG">
<tr>
<td colspan=3 class="ta_01" align="center" bgcolor="#afd1f3"><strong>系统首页</strong></td>
</tr>
<tr>
<td width="65%" height="84" align="center" valign="top" >
<span class="Style1">登录成功!</span>
</td>
</tr>
<tr><td height=2></td></tr>
</table>
</form>
</body>
</html>
add.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<HTML>
<HEAD>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<LINK href="${pageContext.request.contextPath}/css/Style.css" type="text/css" rel="stylesheet">
<script language="javascript" src="${pageContext.request.contextPath}/js/public.js"></script>
<script language="javascript" src="${pageContext.request.contextPath}/js/check.js"></script>
<!-- 日期插件,使用jquery -->
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery/jquery-1.4.2.js"></script>
<link rel="stylesheet" href="${pageContext.request.contextPath}/jquery/jquery.datepick.css" type="text/css">
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery/jquery.datepick.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery/jquery.datepick-zh-CN.js"></script>
</HEAD>
<script type="text/javascript">
$(document).ready(function(){
//使用class属性处理 'yy-mm-dd' 设置格式"yyyy/mm/dd"
$('#birthday').datepick({dateFormat: 'yy-mm-dd'});
});
</script>
<body>
<s:form id="userAction_save_do" name="Form1" action="user_add" namespace="/" method="post" enctype="multipart/form-data">
<table cellSpacing="1" cellPadding="5" width="100%" align="center" bgColor="#eeeeee" style="border: 1px solid #8ba7e3" border="0">
<tr>
<td class="ta_01" align="center" bgColor="#afd1f3" colSpan="4"
height="26">
<strong><STRONG>添加用户</STRONG>
</strong>
</td>
</tr>
<tr>
<td class="ta_01" align="center" bgColor="#afd1f3" colSpan="4"
height="26">
<s:fielderror/>
<s:actionerror/>
</td>
</tr>
<tr>
<td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
登录名:
</td>
<td class="ta_01" bgColor="#ffffff" colspan="3">
<s:textfield name="logonName" value="" id="userAction_save_do_logonName" cssClass="bg"/>
</td>
</tr>
<tr>
<td align="center" bgColor="#f5fafe" class="ta_01">
密码:
</td>
<td class="ta_01" bgColor="#ffffff">
<s:password name="logonPwd" value="" id="logonPwd"/>
</td>
<td align="center" bgColor="#f5fafe" class="ta_01">
用户姓名:
</td>
<td class="ta_01" bgColor="#ffffff">
<s:textfield name="userName" value="" id="userAction_save_do_userName" cssClass="bg"/>
</td>
</tr>
<tr>
<td align="center" bgColor="#f5fafe" class="ta_01">
性别:
</td>
<td class="ta_01" bgColor="#ffffff">
<s:radio list="{'男','女'}" name="sex" id="sex" value="%{'男'}"/>
</td>
<td align="center" bgColor="#f5fafe" class="ta_01">
学历:
</td>
<td class="ta_01" bgColor="#ffffff">
<s:select list="{'博士','硕士','研究生','本科','专科','高中'}" name="education" id="education" headerKey="" headerValue="--选择学历--"></s:select>
</td>
</tr>
<tr>
<td align="center" bgColor="#f5fafe" class="ta_01">
出生日期:
</td>
<td class="ta_01" bgColor="#ffffff">
<s:textfield name="birthday" size="20" value="" readonly="readonly" id="birthday"/>
</td>
<td align="center" bgColor="#f5fafe" class="ta_01">
电话:
</td>
<td class="ta_01" bgColor="#ffffff">
<s:textfield name="telephone" value="" id="telephone"/>
</td>
</tr>
<tr>
<td align="center" bgColor="#f5fafe" class="ta_01">
兴趣爱好:
</td>
<td class="ta_01" bgColor="#ffffff" colSpan="3">
<s:checkboxlist list="{'看电影','旅游','健身','购物','睡觉'}" name="interest"/>
</td>
</tr>
<tr>
<td align="center" bgColor="#f5fafe" class="ta_01">
简历资料:
</td>
<td class="ta_01" bgColor="#ffffff" colSpan="3">
<s:file name="upload" size="30" value="" id="userAction_save_do_upload"/>
</td>
</tr>
<TR>
<TD class="ta_01" align="center" bgColor="#f5fafe">
备注:
</TD>
<TD class="ta_01" bgColor="#ffffff" colSpan="3">
<s:textarea name="remark" cols="30" rows="3" id="userAction_save_do_remark" cssStyle="WIDTH: 96%"/>
</TD>
</TR>
<TR>
<td align="center" colSpan="4" class="sep1">
<img src="${pageContext.request.contextPath}/images/shim.gif">
</td>
</TR>
<tr>
<td class="ta_01" style="WIDTH: 100%" align="center"
bgColor="#f5fafe" colSpan="4">
<s:submit value="确定" id="userAction_save_do_submit" name="submit" cssClass="button_ok"/>
<FONT face="宋体"> </FONT>
<s:reset value="重置" cssClass="button_cancel"/>
<FONT face="宋体"> </FONT>
<INPUT class="button_ok" type="button" οnclick="history.go(-1)" value="返回"/>
<span id="Label1"></span>
</td>
</tr>
</table>
</s:form>
</body>
</HTML>
edit.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<HTML>
<HEAD>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<LINK href="${pageContext.request.contextPath}/css/Style.css" type="text/css" rel="stylesheet">
<script language="javascript" src="${pageContext.request.contextPath}/js/public.js"></script>
<script language="javascript" src="${pageContext.request.contextPath}/js/check.js"></script>
<!-- 日期插件,使用jquery -->
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery/jquery-1.4.2.js"></script>
<link rel="stylesheet" href="${pageContext.request.contextPath}/jquery/jquery.datepick.css" type="text/css">
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery/jquery.datepick.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery/jquery.datepick-zh-CN.js"></script>
</HEAD>
<script type="text/javascript">
$(document).ready(function(){
//使用class属性处理 'yy-mm-dd' 设置格式"yyyy/mm/dd"
$('#birthday').datepick({dateFormat: 'yy-mm-dd'});
});
</script>
<body>
<s:form id="userAction_save_do" name="Form1" action="user_add" namespace="/" method="post" enctype="multipart/form-data">
<table cellSpacing="1" cellPadding="5" width="100%" align="center" bgColor="#eeeeee" style="border: 1px solid #8ba7e3" border="0">
<s:hidden name="userID" value="%{model.userID}"/>
<tr>
<td class="ta_01" align="center" bgColor="#afd1f3" colSpan="4"
height="26">
<strong><STRONG>编辑用户</STRONG>
</strong>
</td>
</tr>
<tr>
<td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
登录名:
</td>
<td class="ta_01" bgColor="#ffffff" colspan="3">
<input type="text" name="logonName" value="caocao" id="userAction_save_do_logonName" class="bg"/>
</td>
</tr>
<tr>
<td align="center" bgColor="#f5fafe" class="ta_01">
密码:
</td>
<td class="ta_01" bgColor="#ffffff">
<input type="password" name="logonPwd" value="123" id="logonPwd"/>
</td>
<td align="center" bgColor="#f5fafe" class="ta_01">
用户姓名:
</td>
<td class="ta_01" bgColor="#ffffff">
<input type="text" name="userName" value="曹操" id="userAction_save_do_userName" class="bg"/>
</td>
</tr>
<tr>
<td align="center" bgColor="#f5fafe" class="ta_01">
性别:
</td>
<td class="ta_01" bgColor="#ffffff">
<input type="radio" name="sex" id="sex男" value="男"/><label for="sex男">男</label>
<input type="radio" name="sex" id="sex女" checked="checked" value="女"/><label for="sex女">女</label>
</td>
<td align="center" bgColor="#f5fafe" class="ta_01">
学历:
</td>
<td class="ta_01" bgColor="#ffffff">
<select name="education" id="education">
<option value=""
>--选择学历--</option>
<option value="博士">博士</option>
<option value="硕士">硕士</option>
<option value="研究生" selected="selected">研究生</option>
<option value="本科">本科</option>
<option value="专科">专科</option>
<option value="高中">高中</option>
</select>
</td>
</tr>
<tr>
<td align="center" bgColor="#f5fafe" class="ta_01">
出生日期:
</td>
<td class="ta_01" bgColor="#ffffff">
<input type="text" name="birthday" size="20" value="2012-03-01" readonly="readonly" id="birthday"/>
</td>
<td align="center" bgColor="#f5fafe" class="ta_01">
电话:
</td>
<td class="ta_01" bgColor="#ffffff">
<input type="text" name="telephone" value="12312121" id="telephone"/>
</td>
</tr>
<tr>
<td align="center" bgColor="#f5fafe" class="ta_01">
兴趣爱好:
</td>
<td class="ta_01" bgColor="#ffffff" colSpan="3">
<input type="checkbox" name="interest" value="看电影" id="interest-1" checked="checked"/>
<label for="interest-1" class="checkboxLabel">看电影</label>
<input type="checkbox" name="interest" value="旅游" id="interest-2" checked="checked"/>
<label for="interest-2" class="checkboxLabel">旅游</label>
<input type="checkbox" name="interest" value="健身" id="interest-3"/>
<label for="interest-3" class="checkboxLabel">健身</label>
<input type="checkbox" name="interest" value="购物" id="interest-4"/>
<label for="interest-4" class="checkboxLabel">购物</label>
<input type="checkbox" name="interest" value="睡觉" id="interest-5"/>
<label for="interest-5" class="checkboxLabel">睡觉</label>
<input type="hidden" id="__multiselect_userAction_save_do_interest" name="__multiselect_interest" value="" />
</td>
</tr>
<tr>
<td align="center" bgColor="#f5fafe" class="ta_01">
简历资料:
</td>
<td class="ta_01" bgColor="#ffffff" colSpan="3">
<input type="file" name="upload" size="30" value="" id="userAction_save_do_upload"/>
</td>
</tr>
<TR>
<TD class="ta_01" align="center" bgColor="#f5fafe">
备注:
</TD>
<TD class="ta_01" bgColor="#ffffff" colSpan="3">
<textarea name="remark" cols="30" rows="3" id="userAction_save_do_remark" style="WIDTH: 96%">的</textarea>
</TD>
</TR>
<TR>
<td align="center" colSpan="4" class="sep1">
<img src="${pageContext.request.contextPath}/images/shim.gif">
</td>
</TR>
<tr>
<td class="ta_01" style="WIDTH: 100%" align="center"
bgColor="#f5fafe" colSpan="4">
<button type="submit" id="userAction_save_do_submit" name="submit" value="确定" class="button_ok">
确定
</button>
<FONT face="宋体"> </FONT>
<button type="reset" value="重置" class="button_cancel">重置</button>
<FONT face="宋体"> </FONT>
<INPUT class="button_ok" type="button" οnclick="history.go(-1)" value="返回"/>
<span id="Label1"></span>
</td>
</tr>
</table>
</s:form>
</body>
</HTML>
error.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<link href="${pageContext.request.contextPath}/css/Style.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style1 {
color: #FF0000;
font-size: 18px;
}
-->
</style>
</head>
<body>
<p>
</p>
<table width="100%" border="0">
<tr>
<th width="18%" height="261" scope="col">
</th>
<th width="53%" scope="col">
<table width="453" height="220" border="0" cellpadding="0"
cellspacing="0">
<tr>
<td height="220" align="center" valign="middle"
background="${pageContext.request.contextPath}/images/loginbg.gif">
<p class="style1">
<font color="red">上传附件错误</font>
</p>
<p>
</p>
</td>
</tr>
<tr>
<td height="220" align="center" valign="middle">
<FONT face="宋体"> </FONT>
<INPUT class="button_ok" type="button" οnclick="history.go(-1)" value="返回"/>
</td>
</tr>
</table>
</th>
<th width="29%" scope="col">
</th>
</tr>
</table>
<p>
</p>
</body>
</html>
list.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<HTML>
<HEAD>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="${pageContext.request.contextPath}/css/Style.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="${pageContext.request.contextPath}/js/public.js"></script>
<script type="text/javascript">
function addUser(){
window.location.href = "${pageContext.request.contextPath}/user/add.jsp";
}
</script>
</HEAD>
<body>
<br>
<s:form id="Form1" name="Form1" action="user_listSelect" namespace="/" method="post">
<table cellSpacing="1" cellPadding="0" width="100%" align="center" bgColor="#f5fafe" border="0">
<TBODY>
<tr>
<td class="ta_01" align="center" bgColor="#afd1f3">
<strong>查 询 条 件</strong>
</td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td height="22" align="center" bgColor="#f5fafe" class="ta_01">
用户姓名
</td>
<td class="ta_01" bgColor="#ffffff">
<s:textfield name="userName" size="15" value="" id="Form1_userName" cssClass="bg"/>
</td>
<td height="22" align="center" bgColor="#f5fafe" class="ta_01">
性别:
</td>
<td class="ta_01" bgColor="#ffffff">
<s:select list="{'男','女'}" name="sex" id="sex" headerKey="" headerValue="--选择性别--"></s:select>
</td>
</tr>
<tr>
<td height="22" align="center" bgColor="#f5fafe" class="ta_01">
学历:
</td>
<td class="ta_01" bgColor="#ffffff">
<s:select list="{'博士','硕士','研究生','本科','专科','高中'}" name="education" id="education" headerKey="" headerValue="--选择学历--"></s:select>
</td>
<td height="22" align="center" bgColor="#f5fafe" class="ta_01">
是否上传简历
</td>
<td class="ta_01" bgColor="#ffffff">
<s:select list="#{'1':'有','2':'无'}" name="isUpload" id="isUpload" headerKey="" headerValue="--请选择--"></s:select>
</td>
</tr>
<tr>
<td width="100" height="22" align="center" bgColor="#f5fafe"
class="ta_01">
</td>
<td class="ta_01" bgColor="#ffffff">
<font face="宋体" color="red"> </font>
</td>
<td align="right" bgColor="#ffffff" class="ta_01"><br><br></td>
<td align="right" bgColor="#ffffff" class="ta_01">
<s:submit id="search" name="search" value="查询" cssClass="button_view"/>
<s:reset name="reset" value="重置" cssClass="button_view"/>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="ta_01" align="center" bgColor="#afd1f3">
<strong>用 户 列 表</strong>
</TD>
</tr>
<tr>
<td class="ta_01" align="right">
<button type="button" id="add" name="add" value="添加" class="button_add" οnclick="addUser()">
添加
</button>
</td>
</tr>
<tr>
<td class="ta_01" align="center" bgColor="#f5fafe">
<table cellspacing="0" cellpadding="1" rules="all"
bordercolor="gray" border="1" id="DataGrid1"
style="BORDER-RIGHT: gray 1px solid; BORDER-TOP: gray 1px solid; BORDER-LEFT: gray 1px solid; WIDTH: 100%; WORD-BREAK: break-all; BORDER-BOTTOM: gray 1px solid; BORDER-COLLAPSE: collapse; BACKGROUND-COLOR: #f5fafe; WORD-WRAP: break-word">
<tr
style="FONT-WEIGHT: bold; FONT-SIZE: 12pt; HEIGHT: 25px; BACKGROUND-COLOR: #afd1f3">
<td align="center" width="18%">
登录名
</td>
<td align="center" width="17%">
用户姓名
</td>
<td align="center" width="8%">
性别
</td>
<td align="center" width="23%">
联系电话
</td>
<td width="11%" align="center">
学历
</td>
<td width="7%" align="center">
编辑
</td>
<td width="7%" align="center">
查看
</td>
<td width="7%" align="center">
删除
</td>
</tr>
<s:iterator value="%{users}" var="u">
<tr οnmοuseοver="this.style.backgroundColor = 'white'"
οnmοuseοut="this.style.backgroundColor = '#F5FAFE';">
<td style="CURSOR: hand; HEIGHT: 22px" align="center"
width="18%">
<s:property value="%{#u.logonName}"/>
</td>
<td style="CURSOR: hand; HEIGHT: 22px" align="center"
width="17%">
<s:property value="%{#u.userName}"/>
</td>
<td style="CURSOR: hand; HEIGHT: 22px" align="center"
width="8%">
<s:property value="%{#u.sex}"/>
</td>
<td style="CURSOR: hand; HEIGHT: 22px" align="center"
width="23%">
<s:property value="%{#u.telephone}"/>
</td>
<td style="CURSOR: hand; HEIGHT: 22px" align="center">
<s:property value="%{#u.education}"/>
</td>
<td align="center" style="HEIGHT: 22px">
<s:url namespace="/" action="user_updateForFind" var="editUrl">
<s:param name="userID" value="%{#u.userID}"/>
</s:url>
<s:a href="%{#editUrl}">
<img src="${pageContext.request.contextPath}/images/i_edit.gif" border="0" style="CURSOR: hand">
</s:a>
</td>
<td align="center" style="HEIGHT: 22px">
<s:url namespace="/" action="user_findById" var="findByIdUrl">
<s:param name="userID" value="%{#u.userID}"/>
</s:url>
<s:a href="%{#findByIdUrl}">
<img src="${pageContext.request.contextPath}/images/button_view.gif" border="0" style="CURSOR: hand">
</s:a>
</td>
<td align="center" style="HEIGHT: 22px">
<s:url namespace="/" action="user_del" var="delUrl">
<s:param name="userID" value="%{#u.userID}"/>
</s:url>
<s:a href="%{#delUrl}">
<img src="${pageContext.request.contextPath}/images/i_del.gif" width="16" height="16" border="0" style="CURSOR: hand">
</s:a>
</td>
</tr>
</s:iterator>
</table>
</td>
</tr>
</TBODY>
</table>
</s:form>
</body>
</HTML>
view.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<HTML>
<HEAD>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<LINK href="${pageContext.request.contextPath}/css/Style.css"
type="text/css" rel="stylesheet">
<script language="javascript"
src="${pageContext.request.contextPath}/js/public.js"></script>
<script type="text/javascript">
function downloadFile(userID){
location.href="${pageContext.request.contextPath}/user_download?userID="+userID;
};
</script>
</HEAD>
<body>
<form id="userAction_save_do" name="Form1"
action="${pageContext.request.contextPath}/user/userAction_save.do"
method="post" enctype="multipart/form-data">
<table cellSpacing="1" cellPadding="5" width="100%" align="center"
bgColor="#eeeeee" style="border: 1px solid #8ba7e3" border="0">
<tr>
<td class="ta_01" align="center" bgColor="#afd1f3" colSpan="4"
height="26"><strong><STRONG>查看用户</STRONG> </strong></td>
</tr>
<tr>
<td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
登录名:</td>
<td class="ta_01" bgColor="#ffffff"><s:property
value="%{model.logonName}" /></td>
<td align="center" bgColor="#f5fafe" class="ta_01">用户姓名:</td>
<td class="ta_01" bgColor="#ffffff"><s:property
value="%{model.userName}" /></td>
</tr>
<tr>
<td align="center" bgColor="#f5fafe" class="ta_01">性别:</td>
<td class="ta_01" bgColor="#ffffff"><s:property
value="%{model.sex}" /></td>
<td align="center" bgColor="#f5fafe" class="ta_01">学历:</td>
<td class="ta_01" bgColor="#ffffff"><s:property
value="%{model.education}" /></td>
</tr>
<tr>
<td align="center" bgColor="#f5fafe" class="ta_01">出生日期:</td>
<td class="ta_01" bgColor="#ffffff"><s:property
value="%{model.birthday}" /></td>
<td align="center" bgColor="#f5fafe" class="ta_01">电话:</td>
<td class="ta_01" bgColor="#ffffff"><s:property
value="%{model.telephone}" /></td>
</tr>
<tr>
<td align="center" bgColor="#f5fafe" class="ta_01">兴趣爱好:</td>
<td class="ta_01" bgColor="#ffffff" colSpan="3"><s:property
value="%{model.interest}" /></td>
</tr>
<tr>
<td align="center" bgColor="#f5fafe" class="ta_01">简历资料:</td>
<td class="ta_01" bgColor="#ffffff" colSpan="3"><a
href="javascript:void(0)"
οnclick="downloadFile('<s:property value="%{model.userID}"/>')"
class="cl_01"> <s:property value="%{model.filename}" /> </a></td>
</tr>
<TR>
<TD class="ta_01" align="center" bgColor="#f5fafe">备注:</TD>
<TD class="ta_01" bgColor="#ffffff" colSpan="3"><s:property
value="%{model.remark}" /></TD>
</TR>
<TR>
<td align="center" colSpan="4" class="sep1"><img
src="${pageContext.request.contextPath}/images/shim.gif"></td>
</TR>
<TR>
<td class="ta_01" style="WIDTH: 100%" align="right"
bgColor="#f5fafe" colSpan="4"><FONT face="宋体"> </FONT>
<INPUT class="button_ok" type="button" οnclick="history.go(-1)"
value="返回" /> <span id="Label1"></span></td>
</TR>
</table>
</form>
</body>
</HTML>
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<jsp:forward page="/login/login.jsp"></jsp:forward>