Home
>
宁夏办公自动化对秘书的影响
>
宁夏jsp办公自动化系统
宁夏jsp办公自动化系统

time:2020-07-22 14:10:02

author:重庆佰鼎科技有限公司

【Font size: big medium smail

本文由重庆佰鼎科技有限公司提供,重点介绍了jsp办公自动化系统相关内容。重庆佰鼎科技有限公司专业提供办公自动化对秘书的影响,上海学办公自动化,办公自动化未来等多项产品服务。本公司长期从事该行业多项服务支持,经过多年的发展,现已成为行业服务的佼佼者。

jsp办公自动化系统一、尚学堂OA系统1. 什么是OA系统?

OA系统(Office Automation),即办公自动化系统,是一种应用于办公领域的新型无纸化办公系统。

它利用计算机、通信等现代化技术来数字化地创建、收集、存储、处理办公任务所需的各种信息,代替办公人员传统的部分手动或重复性业务活动,极大地优化了以往复杂、低效的办公室工作过程,可以最大限度地提高工作效率和质量、改善工作环境。

2.需求分析阶段准备

1)演示项目界面原型

2)展示用例图并说明

3)展示数据库模型图并说明

表结构及关系结构图

4)导入数据库表

导入oracle数据库操作步骤

3. 项目入门-搭建项目框架

1)根据MVC原理,OA项目进行分层

M:model service dao entity

V:view jsp js css html

C:controller Servlet

2)创建项目sxtoa(workspace编码统一修改为utf-8)

3)创建包和文件夹

4)为测试创建专门的source folder

5)JSP按照模块划分 system 人事 expense 报销 inpay 收支 duty 考勤

6)加入jar

gson-2.2.4.jar:可以将object转换为json数据log4j-1.2.16 jar:用来读写XML文件的ojdbc6.jar:连接oracal数据库所需要的7)加入工具类

DBUtil.java BaseServlet

8)加入过滤器(暂不配置)

9)加入界面原型 (采用界面原型的jquery版本)

10)部署项目并测试

4.添加部门

DepartmentServlet接收deptApp页面传来的部门信息,并调用DepartmentService使用DepartmentDao把数据存入到数据库中。如果添加成功则请求转发给显示所有部门的servlet如果添加失败则请求转发给原请求页面重新加载页面信息。并且携带错误信息。被jsp获取,显示。

1)实体类 Department

package com.sxt.entity;

import java.io.Serializable;

/**

* 部门类

* @author 董寒冰

*

*/

public class Department implements Serializable,Comparable{

private static final long serialVersionUID = 1L;

private int deptno; //部门编号

private String deptName;//部门名称

private String location;//部门所在地

public Department() {

super();

// TODO Auto-generated constructor stub

}

public Department(int deptno, String deptName) {

super();

this.deptno = deptno;

this.deptName = deptName;

}

public Department(int deptno, String deptName, String location) {

super();

this.deptno = deptno;

this.deptName = deptName;

this.location = location;

}

public int getDeptno() {

return deptno;

}

public void setDeptno(int deptno) {

this.deptno = deptno;

}

public String getDeptName() {

return deptName;

}

public void setDeptName(String deptName) {

this.deptName = deptName;

}

public String getLocation() {

return location;

}

public void setLocation(String location) {

this.location = location;

}

@Override

public String toString() {

return "Department [deptno=" + deptno + ", deptName=" + deptName

+ ", location=" + location + "]";

}

@Override

public int compareTo(Department other) {

return this.deptno - other.deptno;

}

}2)数据库访问层 Department Dao Department DaoImpl

package com.sxt.dao.impl;

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.util.ArrayList;

import java.util.List;

import com.sxt.dao.DepartmentDao;

import com.sxt.entity.Department;

import com.sxt.util.DBUtil;

public class DepartmentDaoImpl implements DepartmentDao{

@Override

public int save(Department dept) {

String sql = "insert into dept values(?,?,?)";

Object[] params = {dept.getDeptno(),dept.getDeptName(),dept.getLocation()};

return DBUtil.executeUpdate(sql, params);

}

}3)业务层: Department Service Department ServiceImpl

package com.sxt.service.impl;

import java.util.List;

import com.sxt.dao.DepartmentDao;

import com.sxt.dao.impl.DepartmentDaoImpl;

import com.sxt.entity.Department;

import com.sxt.service.DepartmentService;

public class DepartmentServiceImpl implements DepartmentService{

private DepartmentDao deptDao = new DepartmentDaoImpl();

@Override

public int add(Department dept) {

return deptDao.save(dept);

}

}4)Junit测试:

package com.sxt.test;

import java.util.List;

import org.junit.Test;

import com.sxt.entity.Department;

import com.sxt.service.DepartmentService;

import com.sxt.service.impl.DepartmentServiceImpl;

public class TestDepartmentService {

@Test

public void testAdd(){

DepartmentService deptService = new DepartmentServiceImpl();

Department dept = new Department(1,"总裁办","502");

int n = deptService.add(dept);

System.out.println(n);

}

}5)控制层: DepartmentServlet extends BaseServlet

package com.sxt.servlet;

import java.io.IOException;

import java.util.List;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import com.sxt.entity.Department;

import com.sxt.service.DepartmentService;

import com.sxt.service.impl.DepartmentServiceImpl;

public class DepartmentServlet extends BaseServlet {

public void add(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{

//接收视图层的表单数据

int deptno = Integer.parseInt(request.getParameter("deptno"));

String deptName = request.getParameter("deptName");

String location = request.getParameter("location");

Department dept = new Department(deptno, deptName, location);

//调用业务层完成添加操作

DepartmentService deptService = new DepartmentServiceImpl();

int res = deptService.add(dept);

//根据结果不同跳转不同页面

if (res > 0) {

response.sendRedirect("/sxtoa/dept?method=findAll");

}else {

request.setAttribute("error", "添加失败");

request.getRequestDispatcher("/system/deptAdd.jsp").forward(request, response);

}

}

}6)视图层:system/deptAdd.jsp

7)将HTML修改为JSP

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

<%

String path = request.getContextPath();

String basePath = request.getScheme() + "://"

+ request.getServerName() + ":" + request.getServerPort()

+ path + "/";

%>

jsp办公自动化系统

无标题文档

基本信息

  • class="dfinput" />

  • class="dfinput" />

  • class="dfinput" />

  • class="btn" value="确认保存" />

${error }

5.查询所有部门

DepartmentServlet接收mian.html页面传来的a标签链接请求并传递参数method=finAll,DepartmentService使用DepartmentDao把所有部门的数据取出保存在请求实体中。使用请求转发将deptList.jsp数据响应给页面展示出来。

1)开发数据访问层,实现查询所有部门操作

package com.sxt.dao.impl;

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.util.ArrayList;

import java.util.List;

import com.sxt.dao.DepartmentDao;

import com.sxt.entity.Department;

import com.sxt.util.DBUtil;

public class DepartmentDaoImpl implements DepartmentDao{

@Override

public int save(Department dept) {

String sql = "insert into dept values(?,?,?)";

Object[] params = {dept.getDeptno(),dept.getDeptName(),dept.getLocation()};

return DBUtil.executeUpdate(sql, params);

}

@Override

public List findAll() {

Connection connection = null;

PreparedStatement ps = null;

ResultSet rs = null;

List list = new ArrayList<>();

try {

connection = DBUtil.getConnection();

ps = connection.prepareStatement("select * from dept");

rs = ps.executeQuery();

while (rs.next()) {

int deptno = rs.getInt("deptno");

String deptName = rs.getString("deptName");

String location = rs.getString("location");

Department dept = new Department(deptno, deptName, location);

list.add(dept);

}

} catch (Exception e) {

// TODO: handle exception

DBUtil.closeAll(rs, ps, connection);

}

return list;

}

}2)开发业务层,实现查询所有部门操作

package com.sxt.service.impl;

import java.util.List;

import com.sxt.dao.DepartmentDao;

import com.sxt.dao.impl.DepartmentDaoImpl;

import com.sxt.entity.Department;

import com.sxt.service.DepartmentService;

public class DepartmentServiceImpl implements DepartmentService{

private DepartmentDao deptDao = new DepartmentDaoImpl();

@Override

public int add(Department dept) {

return deptDao.save(dept);

}

@Override

public List findAll() {

return deptDao.findAll();

}

}3)使用Junit测试后台查询所有部门操作

@Test

public void testFindAll(){

DepartmentService deptService = new DepartmentServiceImpl();

List list = deptService.findAll();

System.out.println(list);

}4)开发控制层,实现查询所有部门操作

在DepartmentServlet.java添加 findAll 方法

public void findAll(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{

//调用业务层完成添加操作

DepartmentService deptService = new DepartmentServiceImpl();

List deptList = deptService.findAll();

//请求转发

request.setAttribute("deptList", deptList);

request.getRequestDispatcher("/system/deptList.jsp").forward(request, response);

}5)开发视图层,实现显示所有部门操作

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

<%@ taglib prefix="c" uri="Oracle Technology Network for Java Developers" %>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

无标题文档

部门列表

编号部门名称办公地点操作
${dept.deptno }${dept.deptName }${dept.location }修改     

删除

提示信息

是否确认对信息的修改 ?

如果是请点击确定按钮 ,否则请点取消。

 

6. 删除指定部门信息

DepartmentServlet接收deptApp页面传来的要删除的deptno,并调用DepartmentService使用DepartmentDao根据传来的deptno将数据从数据库中删除,并请求转发给显示所有部门的servlet。

1)开发视图层,实现删除部门超链接

删除

function deleteDept(deptno){

if(window.confirm("您确定删除该部门吗?")){

location.href="/sxtoa/dept?method=delete&deptno="+deptno;

}

}2)开发控制层,实现删除部门功能

在DepartmentServlet.java添加 delete 方法

public void delete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{

//接收删除的部门编号

int deptno = Integer.parseInt(request.getParameter("deptno"));

//调用业务层完成添加操作

DepartmentService deptService = new DepartmentServiceImpl();

int res = deptService.delete(deptno);

//跳转

request.getRequestDispatcher("/dept?method=findAll").forward(request, response);

}3)开发业务层,实现删除部门功能

@Override

public int delete(int deptno) {

return deptDao.delete(deptno);

}4)开发数据访问层,实现删除部门功能

@Override

public int delete(int deptno) {

String sql = "delete from dept where deptno=?";

Object[] params = {deptno};

return DBUtil.executeUpdate(sql, params);

}7.添加员工

EmployeeServlet接收empAdd页面传来的form表单信息,并调用DEmployeeService使用EmployeeDao把数据存入到数据库中。如果添加成功则请求转发给显示所有部门的servlet如果添加失败则请求转发给原请求页面重新加载页面信息。并且携带错误信息。被jsp获取,显示。

1)创建Employee实体类

package com.sxt.entity;

import java.util.Date;

import java.util.ArrayList;

import java.util.List;

/**

* 员工类

*

* 如何表示员工所属一个部门、一个岗位、一个上级、甚至多个下级的信息呢?

* 在数据库中通过外键来实现:deptno、posid,mgrid

* 在Java类中通过属性关联来实现

* @author 董寒冰

*

*/

public class Employee {

private String empId;//员工编号

private String password;//密码

private String realName;//真实姓名

private String sex;//性别

private Date birthDate;//出生日期

private Date hireDate;//入职日期

private Date leaveDate;//离职日期

private int onDuty;//是否在职 0-离职 1-在职

private int empType;//员工类型 1.普通员工 2.管理人员 含经理、总监、总裁等 3.管理员

private String phone;//联系方式

private String qq;

private String emerContactPerson;//紧急联系人信息

private String idCard;//身份证号码

private Department dept; //员工所属部门 不仅包含部门的编号,还包含其他信息

private Position position;

private Employee mgr;//上级领导的信息

private List empList = new ArrayList();//下级的信息,可能多个

public Employee() {

super();

// TODO Auto-generated constructor stub

}

public Employee(String empId, String password, String realName, String sex,

Date birthDate, Date hireDate, Date leaveDate, int onDuty,

int empType, String phone, String qq, String emerContactPerson,

String idCard, Department dept, Position position, Employee mgr) {

super();

this.empId = empId;

this.password = password;

this.realName = realName;

this.sex = sex;

this.birthDate = birthDate;

this.hireDate = hireDate;

this.leaveDate = leaveDate;

this.onDuty = onDuty;

this.empType = empType;

this.phone = phone;

this.qq = qq;

this.emerContactPerson = emerContactPerson;

this.idCard = idCard;

this.dept = dept;

this.position = position;

this.mgr = mgr;

}

public Employee(String empId, String password, String realName, String sex,

Date birthDate, Date hireDate, Date leaveDate, int onDuty,

int empType, String phone, String qq, String emerContactPerson,

String idCard, Department dept, Position position, Employee mgr,

List empList) {

super();

this.empId = empId;

this.password = password;

this.realName = realName;

this.sex = sex;

this.birthDate = birthDate;

this.hireDate = hireDate;

this.leaveDate = leaveDate;

this.onDuty = onDuty;

this.empType = empType;

this.phone = phone;

this.qq = qq;

this.emerContactPerson = emerContactPerson;

this.idCard = idCard;

this.dept = dept;

this.position = position;

this.mgr = mgr;

this.empList = empList;

}

@Override

public String toString() {

return "Employee [empId=" + empId + ", password=" + password

+ ", realName=" + realName + ", sex=" + sex + ", birthDate="

+ birthDate + ", hireDate=" + hireDate + ", leaveDate="

+ leaveDate + ", onDuty=" + onDuty + ", empType=" + empType

+ ", phone=" + phone + ", qq=" + qq + ", emerContactPerson="

+ emerContactPerson + ", idCard=" + idCard + ", dept=" + dept

+ ", position=" + position + ", mgr=" + mgr + ", empList="

+ empList + "]";

}

public String getEmpId() {

return empId;

}

public void setEmpId(String empId) {

this.empId = empId;

}

public String getPassword() {

return password;

}

public void setPassword(String password) {

this.password = password;

}

public String getRealName() {

return realName;

}

public void setRealName(String realName) {

this.realName = realName;

}

public String getSex() {

return sex;

}

public void setSex(String sex) {

this.sex = sex;

}

public Date getBirthDate() {

return birthDate;

}

public void setBirthDate(Date birthDate) {

this.birthDate = birthDate;

}

public Date getHireDate() {

return hireDate;

}

public void setHireDate(Date hireDate) {

this.hireDate = hireDate;

}

public Date getLeaveDate() {

return leaveDate;

}

public void setLeaveDate(Date leaveDate) {

this.leaveDate = leaveDate;

}

public int getOnDuty() {

return onDuty;

}

public void setOnDuty(int onDuty) {

this.onDuty = onDuty;

}

public int getEmpType() {

return empType;

}

public void setEmpType(int empType) {

this.empType = empType;

}

public String getPhone() {

return phone;

}

public void setPhone(String phone) {

this.phone = phone;

}

public String getQq() {

return qq;

}

public void setQq(String qq) {

this.qq = qq;

}

public String getEmerContactPerson() {

return emerContactPerson;

}

public void setEmerContactPerson(String emerContactPerson) {

this.emerContactPerson = emerContactPerson;

}

public String getIdCard() {

return idCard;

}

public void setIdCard(String idCard) {

this.idCard = idCard;

}

public Department getDept() {

return dept;

}

public void setDept(Department dept) {

this.dept = dept;

}

public Position getPosition() {

return position;

}

public void setPosition(Position position) {

this.position = position;

}

public Employee getMgr() {

return mgr;

}

public void setMgr(Employee mgr) {

this.mgr = mgr;

}

public List getEmpList() {

return empList;

}

public void setEmpList(List empList) {

this.empList = empList;

}

}2)开发控制层,实现查询所有部门操作

注意:对空数据的判断处理,容易出现空指针的异常

package com.sxt.servlet;

import java.io.IOException;

import java.text.DateFormat;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.List;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import com.sxt.entity.Department;

import com.sxt.entity.Employee;

import com.sxt.entity.Position;

import com.sxt.service.DepartmentService;

import com.sxt.service.EmployeeService;

import com.sxt.service.impl.DepartmentServiceImpl;

import com.sxt.service.impl.EmployeeServiceImpl;

public class EmployeeServlet extends BaseServlet {

public void add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{

//获取员工信息

String empId = request.getParameter("empId");

//默认密码

String password = "12345";

String realName = request.getParameter("realName");

String sex = request.getParameter("sex");

//日期处理

String sbirthDate = request.getParameter("birthDate");

String shireDate = request.getParameter("hireDate");

String sleaveDate = request.getParameter("leaveDate");

Date birthDate = null, hireDate = null, leaveDate = null;

DateFormat df = new SimpleDateFormat("yyyy-MM-dd");

try {

birthDate = df.parse(sbirthDate);

} catch (ParseException e) {

e.printStackTrace();

}

try {

hireDate = df.parse(shireDate);

} catch (ParseException e) {

e.printStackTrace();

}

try {

if (sleaveDate != "") {

leaveDate = df.parse(sleaveDate);

}

} catch (ParseException e) {

e.printStackTrace();

}

int onDuty = Integer.parseInt(request.getParameter("onDuty"));

int empType = Integer.parseInt(request.getParameter("empType"));

String phone = request.getParameter("phone");

String qq = request.getParameter("qq");

String emerContactPerson = request.getParameter("emerContactPerson");

String idCard = request.getParameter("idCard");

//对象的处理

Department dept = new Department();

dept.setDeptno(Integer.parseInt(request.getParameter("deptno")));

Position position = new Position();

position.setPosId(Integer.parseInt(request.getParameter("posId")));

Employee mgr = new Employee();

mgr.setEmpId(request.getParameter("mgrId"));

Employee emp = new Employee(empId, password, realName, sex, birthDate, hireDate,

leaveDate, onDuty, empType, phone, qq, emerContactPerson, idCard, dept,

position, mgr);

//调用业务层完成添加操作

EmployeeService empService = new EmployeeServiceImpl();

int res = empService.add(emp);

//根据结果进行页面跳转

if (res > 0) {

response.sendRedirect("/sxtoa/emp?method=findAll");

}else {

request.setAttribute("error", "添加员工失败");

request.getRequestDispatcher("/system/empAdd.jsp").forward(request, response);

}

}

}3)开发业务层,实现查询所有部门操作

package com.sxt.service.impl;

import java.util.Date;

import java.util.List;

import com.sxt.dao.EmployeeDao;

import com.sxt.dao.impl.EmployeeDaoImpl;

import com.sxt.entity.Employee;

import com.sxt.service.EmployeeService;

public class EmployeeServiceImpl implements EmployeeService{

private EmployeeDao empDao = new EmployeeDaoImpl();

@Override

public int add(Employee emp) {

return empDao.save(emp);

}

}4)开发数据访问层,实现查询所有部门操作

package com.sxt.dao.impl;

import java.sql.Connection;

import java.sql.Date;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.ArrayList;

import java.util.List;

import com.sxt.dao.EmployeeDao;jsp办公自动化系统

import com.sxt.entity.Department;

import com.sxt.entity.Employee;

import com.sxt.entity.Position;

import com.sxt.util.DBUtil;

public class EmployeeDaoImpl implements EmployeeDao{

@Override

public int save(Employee emp) {

String sql = "insert into employee values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

Date leaveDate = null;

if (emp.getLeaveDate() != null) {

leaveDate = new Date(emp.getLeaveDate().getTime());

}

Object[] params = {emp.getEmpId(),emp.getPassword(),emp.getDept().getDeptno(),

emp.getPosition().getPosId(),emp.getMgr().getEmpId(),emp.getRealName(),

emp.getSex(),new Date(emp.getBirthDate().getTime()),new Date(emp.getHireDate().getTime()),

leaveDate,emp.getOnDuty(),emp.getEmpType(),emp.getPhone(),

emp.getQq(),emp.getEmerContactPerson(),emp.getIdCard()};

return DBUtil.executeUpdate(sql, params);

}5)开发视图层,实现显示所有部门操作

html页面和jsp页面的区别html页面是静态页面,可以使用html+css+js实现页面的各种效果,jsp页面是Java服务端的页面,是动态的,需要经过JDK编译后把内容发给客户端去显示。HTML能直接打开,jsp只能发布到Tomact等服务器上才能打开 。在jsp中用<%%>就可以写Java代码了,而html没有<%%>,html中不能编写java代码。<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="Oracle Technology Network for Java Developers" %>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

无标题文档

基本信息

  • 男    

    也可以根据身份证号自动获取

  • 也可以根据身份证号自动获取

  • 是    

  • 基层员工    

    各级管理人员

  •   

${error }

Reprint please indicate:http://oybw.cnsoftweb.com/bgzdh-3036.html