首页 > 代码库 > javaEE mvc例子详解

javaEE mvc例子详解


一个不错的例子值得细细品味:

下面按照包顺序将代码贴出来供大家参考:

IEmpDAO

package org.lzch.dao;

import java.util.List;

import org.lzch.vo.Emp;

public interface IEmpDAO {
	public boolean doCreate(Emp emp)throws Exception;
	public boolean doUpdate(Emp emp)throws Exception;
	public boolean doDelete(int empno)throws Exception;
	public List findAll(int currentPage,int lineSize,String keyword)throws Exception;
	public int getAllCount(String keyword)throws Exception;
	public Emp findEmpById(int empno)throws Exception;
	public boolean getAllEname(String ename)throws Exception;
}

EmpDAOImpl

package org.lzch.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import org.lzch.dao.IEmpDAO;
import org.lzch.vo.Emp;

public class EmpDAOImpl implements IEmpDAO {
	private Connection conn=null;
	public EmpDAOImpl(Connection conn){
		this.conn=conn;
	}
	//添加用户信息
	public boolean doCreate(Emp emp) throws Exception {
		// TODO Auto-generated method stub
		boolean flag=false;
		PreparedStatement pstmt=null;
		try{
			this.conn.setAutoCommit(false);		//手动提交
			String sql="INSERT INTO emp1(empno,ename,job,hiredate,sal,comm,photo)VALUES(?,?,?,?,?,?,?)";
			pstmt=this.conn.prepareStatement(sql);
			pstmt.setInt(1, emp.getEmpno());
			pstmt.setString(2, emp.getEname());
			pstmt.setString(3, emp.getJob());
			pstmt.setDate(4, new java.sql.Date(emp.getHiredate().getTime()));
			pstmt.setFloat(5, emp.getSal());
			pstmt.setFloat(6, emp.getComm());
			pstmt.setString(7, emp.getPhoto());
			int count=pstmt.executeUpdate();
			this.conn.commit();		//提交
			if(count>0){
				flag=true;
			}
		}catch(Exception e){
			this.conn.rollback();
		}finally{
			try{
				pstmt.close();
			}catch(Exception e){
				throw e;
			}
		}
		return flag;
	}
	//删除
	public boolean doDelete(int empno) throws Exception {
		// TODO Auto-generated method stub
		boolean flag=false;
		PreparedStatement pstmt=null;
		try{
			String sql="DELETE FROM emp1 WHERE empno=?";
			pstmt=this.conn.prepareStatement(sql);
			pstmt.setInt(1, empno);
			int count=pstmt.executeUpdate();
			if(count>0){
				flag=true;
			}
		}catch(Exception e){
			throw e;
		}finally{
			try{
				pstmt.close();
			}catch(Exception e){
				throw e;
			}
		}
		return flag;
	}
	//更新
	public boolean doUpdate(Emp emp) throws Exception {
		// TODO Auto-generated method stub
		boolean flag=false;
		PreparedStatement pstmt=null;
		try{
			String sql="UPDATE emp1 SET ename=?,job=?,hiredate=?,sal=?,comm=?,photo=? WHERE empno=?";
			pstmt=this.conn.prepareStatement(sql);
			pstmt.setString(1, emp.getEname());
			pstmt.setString(2, emp.getJob());
			pstmt.setDate(3, new java.sql.Date(emp.getHiredate().getTime()));
			pstmt.setFloat(4, emp.getSal());
			pstmt.setFloat(5, emp.getComm());
			pstmt.setString(6, emp.getPhoto());
			pstmt.setInt(7, emp.getEmpno());
			int count=pstmt.executeUpdate();
			System.out.println("emp_UPDATE_SQL==="+sql);
			if(count>0){
				flag=true;
			}
		}catch(Exception e){
			throw e;
		}finally{
			try{
				pstmt.close();
			}catch(Exception e){
				throw e;
			}
		}
		return flag;
	}
	//查询全部信息
	public List findAll(int currentPage, int lineSize, String keyword)
			throws Exception {
		// TODO Auto-generated method stub
		List all=new ArrayList();
		PreparedStatement pstmt=null;
		String sql=null;
		if(keyword==null||"".equals(keyword)){
			sql="SELECT TOP "+lineSize+" empno,ename,job,hiredate,sal,comm,photo FROM " +
				"(SELECT TOP "+lineSize+" empno,ename,job,hiredate,sal,comm,photo FROM " +
				"(SELECT TOP "+currentPage*lineSize+" * FROM emp1 ORDER BY empno ASC)temptlb1 ORDER BY empno DESC)temptlb2 ORDER BY empno asc";
		}else{
			sql="SELECT empno,ename,job,hiredate,sal,comm,photo FROM emp1 WHERE empno LIKE '%"+keyword+"%' " +
				"OR ename LIKE '%"+keyword+"%' OR job LIKE '%"+keyword+"%' OR hiredate LIKE '%"+keyword+"%'" +
				" OR sal LIKE '%"+keyword+"%' OR comm LIKE '%"+keyword+"%' ";
		}
		try{
			pstmt=this.conn.prepareStatement(sql);
//			pstmt.setString(1, "%"+keyword+"%");
//			pstmt.setString(2, "%"+keyword+"%");
//			pstmt.setString(3, "%"+keyword+"%");
//			pstmt.setString(4, "%"+keyword+"%");
//			pstmt.setString(5, "%"+keyword+"%");
//			pstmt.setString(6, "%"+keyword+"%");
			System.out.println(sql);
			ResultSet rs=pstmt.executeQuery();
			Emp emp=null;
			while(rs.next()){
				emp=new Emp();
				emp.setEmpno(rs.getInt(1));
				emp.setEname(rs.getString(2));
				emp.setJob(rs.getString(3));
				emp.setHiredate(rs.getDate(4));
				emp.setSal(rs.getFloat(5));
				emp.setComm(rs.getFloat(6));
				emp.setPhoto(rs.getString(7));
				all.add(emp);
			}
		}catch(Exception e){
			throw e;
		}finally{
			try{
				pstmt.close();
			}catch(Exception e){
				throw e;
			}
		}
		return all;
	}
	//按ID查询
	public Emp findEmpById(int empno) throws Exception {
		// TODO Auto-generated method stub
		Emp emp=null;
		PreparedStatement pstmt=null;
		try{
			String sql="SELECT empno,ename,job,hiredate,sal,comm,photo FROM emp1 WHERE empno=?";
			pstmt=this.conn.prepareStatement(sql);
			pstmt.setInt(1, empno);
			ResultSet rs=pstmt.executeQuery();
			if(rs.next()){
				emp=new Emp();
				emp.setEmpno(rs.getInt(1));
				emp.setEname(rs.getString(2));
				emp.setJob(rs.getString(3));
				emp.setHiredate(rs.getDate(4));
				emp.setSal(rs.getFloat(5));
				emp.setComm(rs.getFloat(6));
				emp.setPhoto(rs.getString(7));
			}
		}catch(Exception e){
			throw e;
		}finally{
			try{
				pstmt.close();
			}catch(Exception e){
				throw e;
			}
		}
		return emp;
	}
	//查询数据表里  记录集
	public int getAllCount(String keyword) throws Exception {
		// TODO Auto-generated method stub
		int count=0;
		PreparedStatement pstmt=null;
		try{
			String sql="SELECT COUNT(empno) FROM emp1 WHERE empno LIKE ? OR ename LIKE ? " +
						"OR job LIKE ? OR hiredate LIKE ? OR sal LIKE ? OR comm LIKE ? OR photo LIKE ? ";
			pstmt=this.conn.prepareStatement(sql);
			pstmt.setString(1, "%"+keyword+"%");
			pstmt.setString(2, "%"+keyword+"%");
			pstmt.setString(3, "%"+keyword+"%");
			pstmt.setString(4, "%"+keyword+"%");
			pstmt.setString(5, "%"+keyword+"%");
			pstmt.setString(6, "%"+keyword+"%");
			pstmt.setString(7, "%"+keyword+"%");
			ResultSet rs=pstmt.executeQuery();
			if(rs.next()){
				count=rs.getInt(1);			//返回数据表里的所有数据集		geeInt(1):方法,查询表里所有数据集
			}
		}catch(Exception e){
			throw e;
		}finally{
			try{
				pstmt.close();
			}catch(Exception e){
				throw e;
			}
		}
		return count;
	}
	//验证用户名是否存在
	public boolean getAllEname(String ename)throws Exception{
		boolean flag=false;
		PreparedStatement pstmt=null;
		try{
			String sql="SELECT COUNT(ename) FROM emp1 WHERE ename=?";
			pstmt=this.conn.prepareStatement(sql);
			pstmt.setString(1, ename);
			ResultSet rs=pstmt.executeQuery();
			if(rs.next()){
				if(rs.getInt(1)>0){
					flag=true;
					System.out.println("impl===flag=="+rs.getInt(1));
					System.out.println("impl===flag=="+flag);
				}else{
					flag=false;
				}
			}
		}catch(Exception e){
			throw e;
		}finally{
			try{
				pstmt.close();
			}catch(Exception e){
				throw e;
			}
		}
		return flag;
	}
}

EmpDAOProxy

package org.lzch.dao.proxy;

import java.util.List;

import org.lzch.dao.IEmpDAO;
import org.lzch.dao.impl.EmpDAOImpl;
import org.lzch.dbc.DatabaseConnection;
import org.lzch.vo.Emp;

public class EmpDAOProxy implements IEmpDAO {
	private DatabaseConnection dbc=null;
	private IEmpDAO dao=null;
	int count=0;
	public EmpDAOProxy(){
		try{
			this.dbc=new DatabaseConnection();
		}catch(Exception e){
			e.printStackTrace();
		}
		this.dao=new EmpDAOImpl(this.dbc.getConnection());
	}
	
	public boolean doCreate(Emp emp) throws Exception {
		// TODO Auto-generated method stub
		boolean flag=false;
		try{
			if(this.dao.findEmpById(emp.getEmpno())==null){
				flag=this.dao.doCreate(emp);			//调用真实主题类
			}
		}catch(Exception e){
			throw e;
		}finally{
			try{
				this.dbc.closeConnection();
			}catch(Exception e){
				throw e;
			}
		}
		return flag;
	}

	public boolean doDelete(int empno) throws Exception {
		// TODO Auto-generated method stub
		boolean flag=false;
		try{
			flag=this.dao.doDelete(empno);				//调用真实主题类
		}catch(Exception e){
			throw e;
		}finally{
			try{
				this.dbc.closeConnection();
			}catch(Exception e){
				throw e;
			}
		}
		return flag;
	}

	public boolean doUpdate(Emp emp) throws Exception {
		// TODO Auto-generated method stub
		boolean flag=false;
		try{
			flag=this.dao.doUpdate(emp);			//调用真实主题类
		}catch(Exception e){
			throw e;
		}finally{
			try{
				this.dbc.closeConnection();
			}catch(Exception e){
				throw e;
			}
		}
		return flag;
	}

	public List findAll(int currentPage, int lineSize, String keyword)
			throws Exception {
		// TODO Auto-generated method stub
		List all=null;
		try{
			all=this.dao.findAll(currentPage, lineSize, keyword);		//调用真实主题类
			count=this.dao.getAllCount(keyword);		//取得最大记录数   //调用真实主题类
		}catch(Exception e){
			throw e;
		}finally{
			try{
				this.dbc.closeConnection();
			}catch(Exception e){
				throw e;
			}
		}
		return all;
	}

	public Emp findEmpById(int empno) throws Exception {
		// TODO Auto-generated method stub
		Emp emp=null;
		try{
			emp=this.dao.findEmpById(empno);			//调用真实主题类
		}catch(Exception e){
			throw e;
		}finally{
			try{
				this.dbc.closeConnection();
			}catch(Exception e){
				throw e;
			}
		}
		return emp;
	}

	public int getAllCount(String keyword) throws Exception {
		// TODO Auto-generated method stub
		return this.count;
	}
	
	public boolean getAllEname(String ename)throws Exception{
		boolean flag=false;
		try{
			flag=this.dao.getAllEname(ename);
		}catch(Exception e){
			throw e;
		}finally{
			try{
				this.dbc.closeConnection();
			}catch(Exception e){
				throw e;
			}
		}
		return flag;
	}
}

DatabaseConnection

package org.lzch.dbc;

import java.sql.Connection;
import java.sql.DriverManager;

public class DatabaseConnection {
	private static final String DBDRIVER="com.microsoft.sqlserver.jdbc.SQLServerDriver";
	private static final String DBURL="jdbc:sqlserver://localhost:1433;DatabaseName=login";
	private static final String DBUSER="sa";
	private static final String DBPASSWORD="000000";
	private Connection conn=null;
	public DatabaseConnection(){
		try{
			Class.forName(DBDRIVER);
			this.conn=DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public Connection getConnection(){
		return this.conn;
	}
	public void closeConnection(){
		if(this.conn!=null){
			try{
				this.conn.close();
			}catch(Exception e){
				e.printStackTrace();
			}
		}
	}
}

DAOFactory

package org.lzch.factory;

import org.lzch.dao.IEmpDAO;
import org.lzch.dao.proxy.EmpDAOProxy;

public class DAOFactory {
	public static IEmpDAO getIEmpDAOInstance(){
		return new EmpDAOProxy();
	}
}

EmpEncodingFilter

package org.lzch.filter;


import java.io.IOException;


import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;


public class EmpEncodingFilter implements Filter {
	private String charset=null;
	public void destroy() {
		// TODO Auto-generated method stub


	}


	public void doFilter(ServletRequest req, ServletResponse resp,
			FilterChain chain) throws IOException, ServletException {
		// TODO Auto-generated method stub
		req.setCharacterEncoding(this.charset);
		chain.doFilter(req, resp);
	}


	public void init(FilterConfig config) throws ServletException {
		// TODO Auto-generated method stub
		this.charset=config.getInitParameter("charset");
	}


}

EmpServlet

package org.lzch.servlet;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lzch.factory.DAOFactory;
import org.lzch.util.IPTimeStamp;
import org.lzch.vo.Emp;

import com.jspsmart.upload.SmartUpload;

public class EmpServlet extends HttpServlet {
	public void service(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException{
		String p=req.getParameter("p");
		if(p.equals("emp_insert")){
			this.doCreate(req, resp);
		}
		if(p.equals("doUpdatePage")){
			this.doUpdatePage(req, resp);
		}
		if(p.equals("doUpdate")){
			this.doUpdate(req, resp);
		}
		if(p.equals("doDelete")){
			this.doDelete(req, resp);
		}
		if(p.equals("getAllEname")){
			this.getAllEname(req, resp);
		}
	}
	public void doCreate(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException{
		List all=new ArrayList();
		SmartUpload smart=new SmartUpload();
		Emp emp=new Emp();
		int empno=0;
		String ename=null;
		String job=null;
		Date hiredate=null;
		float sal=0.0f;
		float comm=0.0f;
		String photo="nophoto.jpg";
		try{
			smart.initialize(this.getServletConfig(),req,resp);			//初始化上传
			smart.upload();						//准备上传
			
			empno=Integer.parseInt(smart.getRequest().getParameter("empno"));
			ename=smart.getRequest().getParameter("ename");
			job=smart.getRequest().getParameter("job");
			hiredate=new SimpleDateFormat("yyyy-mm-dd").parse(smart.getRequest().getParameter("hiredate"));
			sal=Float.parseFloat(smart.getRequest().getParameter("sal"));
			comm=Float.parseFloat(smart.getRequest().getParameter("comm"));
			if(smart.getFiles().getFile(0).getSize()>0){		//判断是否有上传文件
				IPTimeStamp its=new IPTimeStamp(req.getRemoteAddr());
				//拼凑上传文件名称
				photo=its.getIPTimeStampRand()+"."+smart.getFiles().getFile(0).getFileExt();
			}
			emp.setEmpno(empno);
			emp.setEname(ename);
			emp.setJob(job);
			emp.setHiredate(hiredate);
			emp.setSal(sal);
			emp.setComm(comm);
			emp.setPhoto(photo);
			if(DAOFactory.getIEmpDAOInstance().doCreate(emp)){
				if(smart.getFiles().getFile(0).getSize()>0){
					//添加成功,保存上传文件
					smart.getFiles().getFile(0).saveAs(getServletContext().getRealPath("/")+"jsp/upload/"+photo);
				}
				all.add("职员信息添加成功!");
			}else{
				all.add("职员信息添加失败!");
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		req.setAttribute("infoInsert", all);
		req.getRequestDispatcher("jsp/admin/emp/emp_insert_do.jsp").forward(req, resp);
	}
	public void doUpdatePage(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException{
		int empno=0;
		Emp emp=null;
		try{
			empno=Integer.parseInt(req.getParameter("empno"));
			emp=DAOFactory.getIEmpDAOInstance().findEmpById(empno);
		}catch(Exception e){
			e.printStackTrace();
		}
		req.setAttribute("infoUpdatePage", emp);
		req.getRequestDispatcher("jsp/admin/emp/emp_update.jsp").forward(req, resp);
	}
	public void doUpdate(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException{
		List all=new ArrayList();
		SmartUpload smart=new SmartUpload();
		Emp emp=new Emp();
		
		int empno=0;
		String ename=null;
		String job=null;
		Date hiredate=null;
		float sal=0.0f;
		float comm=0.0f;
		String photo=smart.getRequest().getParameter("pic");
		
		try{
			smart.initialize(getServletConfig(),req,resp);		//初始化上传
			smart.upload();						//准备上传
			
			empno=Integer.parseInt(smart.getRequest().getParameter("empno"));
			ename=smart.getRequest().getParameter("ename");
			job=smart.getRequest().getParameter("job");
			hiredate=new SimpleDateFormat("yyyy-mm-dd").parse(smart.getRequest().getParameter("hiredate"));
			sal=Float.parseFloat(smart.getRequest().getParameter("sal"));
			comm=Float.parseFloat(smart.getRequest().getParameter("comm"));
			if(smart.getFiles().getFile(0).getSize()>0){
				IPTimeStamp its=new IPTimeStamp(req.getRemoteAddr());
				photo=its.getIPTimeStampRand()+"."+smart.getFiles().getFile(0).getFileExt();		//拼凑上传文件名称
			}
			emp.setEmpno(empno);
			emp.setEname(ename);
			emp.setJob(job);
			emp.setHiredate(hiredate);
			emp.setSal(sal);
			emp.setComm(comm);
			emp.setPhoto(photo);
			if(DAOFactory.getIEmpDAOInstance().doUpdate(emp)){
				if(smart.getFiles().getFile(0).getSize()>0){
					//保存上传文件
					smart.getFiles().getFile(0).saveAs(getServletContext().getRealPath("/")+"jsp/upload/"+photo);
				}
				all.add("员工信息修改成功!");
			}else{
				all.add("员工信息修改失败!");
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		req.setAttribute("infoUpdate", all);
		req.getRequestDispatcher("jsp/admin/emp/emp_update_do.jsp").forward(req, resp);
	}
	public void doDelete(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException{
		int empno=0;
		String photo=null;
		List all=new ArrayList();
		try{
			empno=Integer.parseInt(req.getParameter("empno"));
			photo=req.getParameter("photo");
			System.out.println("photo=="+photo);
			if(DAOFactory.getIEmpDAOInstance().doDelete(empno)){
				if(!(photo.equals("nophoto.jpg"))){
					File f=new File(this.getServletContext().getRealPath("/")+"jsp/upload/"+photo);		//找到当前文件
					System.out.println("当前文件是否存在=="+f.exists());
					if(f.exists()){			//判断当前文件或者文件目录是否存在,则
						f.delete();			//则进行删除
					}
				}
				all.add("文件删除成功!");
			}else{
				all.add("文件删除失败!");
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		req.setAttribute("infoDelete", all);
		req.getRequestDispatcher("jsp/admin/emp/emp_delete_do.jsp").forward(req, resp);
	}
	public void getAllEname(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException{
		req.setCharacterEncoding("gb2312");
		resp.setContentType("text/html;charset=gb2312");
		String ename=null;
		PrintWriter out=resp.getWriter();
		try{
			System.out.println("++++++后台取javascript传递参数++++++++"+req.getParameter("ename"));
//1.String name = URLDecoder.decode("客户端传输过来的中文字符","UTF-8");  			
			ename=URLDecoder.decode(req.getParameter("ename"),"gb2312");
			System.out.println("********servlet********"+ename);
			if(DAOFactory.getIEmpDAOInstance().getAllEname(ename)){
				out.print("true");
			}else{
				out.print("false");
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}

Test

package org.lzch.test;

import java.util.Date;

import org.lzch.vo.Emp;
import org.lzch.factory.DAOFactory;

public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Emp emp=new Emp();
		emp.setEmpno(79);
		emp.setEname("lzch");
		emp.setJob("工程师");
		emp.setHiredate(new Date());
		emp.setSal(5555.5f);
		emp.setComm(350.9f);
		emp.setPhoto("nophoto.jpg");
		try{
			if(DAOFactory.getIEmpDAOInstance().doCreate(emp)){
				System.out.println("插入成功!");
			}else{
				System.out.println("插入失败!");
			}
				
		}catch(Exception e){
			e.printStackTrace();
		}
	}

}

IPTimeStamp

package org.lzch.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class IPTimeStamp {
	private String ip=null;
	public IPTimeStamp(String ip){
		this.ip=ip;
	}
	//上传文件命名:IP+时间戳+3位随机数
	public String getIPTimeStampRand(){
		StringBuffer buf=new StringBuffer();
		//添加当前IP地址
		if(this.ip!=null){
			String str[]=this.ip.split("\\.");		//进行拆分IP地址
			for(int i=0;i<str.length;i++){			
				buf.append(this.addZero(str[i], 3));	//位数不够3位的,进行补0操作
			}
		}
		//添加时间戳
		buf.append(this.getTimeStamp());
		//添加3为随机数
		Random ran=new Random();
		for(int i=0;i<3;i++){		//循环3次
			buf.append(ran.nextInt(10));		//取得一位0到10之间的随机整数
		}
		return buf.toString();
	}
	//补0操作
	public String addZero(String str,int len){
		StringBuffer buf=new StringBuffer();
		buf.append(str);
		while(buf.length()<len){
			buf.insert(0, "0");			//进行添加0操作
		}
		return buf.toString();
	}
	//时间戳
	public String getTimeStamp(){
		SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmssSSS");		//取得当前时间
		return sdf.format(new Date());
	}
}

Emp

package org.lzch.vo;

import java.util.Date;

public class Emp {
	private int empno;
	private String ename;
	private String job;
	private Date hiredate;
	private float sal;
	private float comm;
	private String photo;
	public float getComm() {
		return comm;
	}
	public void setComm(float comm) {
		this.comm = comm;
	}
	public int getEmpno() {
		return empno;
	}
	public void setEmpno(int empno) {
		this.empno = empno;
	}
	public String getEname() {
		return ename;
	}
	public void setEname(String ename) {
		this.ename = ename;
	}
	public Date getHiredate() {
		return hiredate;
	}
	public void setHiredate(Date hiredate) {
		this.hiredate = hiredate;
	}
	public String getJob() {
		return job;
	}
	public void setJob(String job) {
		this.job = job;
	}
	public String getPhoto() {
		return photo;
	}
	public void setPhoto(String photo) {
		this.photo = photo;
	}
	public float getSal() {
		return sal;
	}
	public void setSal(float sal) {
		this.sal = sal;
	}
	
}

emp_delete_do.jsp

<%@page pageEncoding="GBK" contentType="text/html; charset=GBK" %>
<%@page import="java.util.List,java.util.Iterator" %>
<html>
<head>
<title>删除</title>
</head>
<script type="text/javascript">
	opener.window.location.reload() ;		//重新读取,刷新
	function closeWin(){
		window.close();
	}
</script>
<body>
	<center>
	<h2>职员管理程序</h2>
	<hr>
		<%
			List all=(List)request.getAttribute("infoDelete");
			Iterator iter=all.iterator();
			while(iter.hasNext()){
		%>
			<h2><%=iter.next() %></h2>
		<%		
			}
		%>
	<h2><a href=http://www.mamicode.com/"#" onclick="closeWin()">关闭窗口>
emp_insert_do.jsp

<%@page pageEncoding="GBK" contentType="text/html; charset=GBK" %>
<%@page import="java.util.List,java.util.Iterator" %>
<html>
<head>
<title>注册页面</title>
</head>
<script type="text/javascript">
	opener.window.location.reload() ;		//重新读取,刷新
	function closeWin(){
		window.close();
	}
</script>
<body>
	<center>
		<h2>职员管理程序</h2>
		<hr>
	<%
		List all=(List)request.getAttribute("infoInsert");
		Iterator iter=all.iterator();
		while(iter.hasNext()){
	%>
			<h2><%=iter.next() %></h2>
	<%		
		}
	%>
	<h2><a href=http://www.mamicode.com/"#" onclick="closeWin()">关闭窗口>
emp_insert.jsp

<%@page pageEncoding="GBK" contentType="text/html; charset=GBK" %>
<html>
<head>
<title>职员注册页面</title>
</head>
<script type="text/javascript" src=http://www.mamicode.com/js/data.js"></script>>
emp_list.jsp

<%@page pageEncoding="GBK" contentType="text/html; charset=GBK" %>
<%@page import="java.util.List,java.util.Iterator" %>
<%@page import="org.lzch.vo.Emp" %>
<%@page import="org.lzch.dao.proxy.EmpDAOProxy,org.lzch.dao.IEmpDAO" %>
<html>
<head>
<title>职员查询程序</title>
</head>
<style>
	body,td{
		font-size:13px;
	}
</style>
<script type="text/javascript" src=http://www.mamicode.com/js/data.js"></script>>
emp_update_do.jsp

<%@page pageEncoding="GBK" contentType="text/html; charset=GBK" %>
<%@page import="java.util.List,java.util.Iterator" %>
<html>
<head>
<title>修改</title>
</head>
<script type="text/javascript">
	opener.window.location.reload() ;		//重新读取,刷新
	function closeWin(){
		window.close();
	}
</script>
<body>
	<center>
	<h2>职员管理程序</h2>
	<hr>
		<%
			List all=(List)request.getAttribute("infoUpdate");
			Iterator iter=all.iterator();
			while(iter.hasNext()){
		%>
				<h2><%=iter.next() %></h2>
		<%		
			}
		%>
	<h2><a href=http://www.mamicode.com/"#" onclick="closeWin()">关闭窗口>
emp_update.jsp

<%@page pageEncoding="GBK" contentType="text/html; charset=GBK" %>
<%@page import="org.lzch.vo.Emp" %>
<html>
<head>
<title>更新页面</title>
</head>
<script type="text/javascript" src=http://www.mamicode.com/js/data.js"></script>>
split_page.jsp

<%@ page contentType="text/html;charset=GBK"%>
<%@ page import="java.util.*"%>
<%--
	只需要在需要分页的地方导入此页面即可
<jsp:include page="split_page.jsp">
	<jsp:param name="currentPage" value=http://www.mamicode.com/""/>>
web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	<display-name>
	TestJava2</display-name>
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>default.jsp</welcome-file>
	</welcome-file-list>
	
	<filter>
		<filter-name>empEncoding</filter-name>
		<filter-class>org.lzch.filter.EmpEncodingFilter</filter-class>
		<init-param>
			<param-name>charset</param-name>
			<param-value>gb2312</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>empEncoding</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	
	<servlet>
		<servlet-name>empServlet</servlet-name>
		<servlet-class>org.lzch.servlet.EmpServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>empServlet</servlet-name>
		<url-pattern>/EmpServlet</url-pattern>
	</servlet-mapping>
</web-app>

emp.sql

CREATE TABLE emp1(
	empno int not null PRIMARY KEY,
	ename varchar(20),
	job		varchar(10),
	hiredate  datetime,
	sal		float,
	comm	float,
	photo	varchar(20)
)


资源链接:http://download.csdn.net/detail/qilixiang012/7387063