```mysql
# 数据库名称:CompanyManager
create database CompanyManager charset utf8;
use CompanyManager;
# 表: Dept (部门信息表)
create table Dept
(
DeptID int primary key auto_increment, # 部门编号主键,自动增长列
DeptName varchar(20) not null # 部门名称 不允许为空
);
insert into Dept
values (0, '后勤部'),
(0, '法务部'),
(0, '开发部'),
(0, '人力部'),
(0, '财务部');
# 表:Emp (员工信息表)
create table Emp
(
EmpID int primary key auto_increment, # 员工编号主键,自动增长列
EmpName varchar(20) not null, # 员工姓名 不允许为空
Sex char(2) not null, # 性别不允许为空
Age int not null, # 员工年龄不允许为空
Tel varchar(20) unique not null, # 联系电话 不允许为空(唯一约束)
PassWord varchar(12) not null, # 密码 不允许为空
DeptID int,
foreign key (DeptID) references Dept (DeptID)# 部门编号外键,关联部门表DeptID字段
);
insert into Emp
values (0, '季川', '男', 22, '1516816', '123', 1),
(0, '梓兰', '女', 23, '1515530', '456', 4),
(0, '华容', '女', 25, '1805862', '789', 2),
(0, '李铭', '男', 23, '1348028', '023', 5),
(0, '季静', '女', 21, '1516658', '112', 3);
```
```java
package bean;
public class Dept {
private int deptId;
private String deptName;
public Dept(int empId) {
}
public int getDeptId() {
return deptId;
}
public void setDeptId(int deptId) {
this.deptId = deptId;
}
public String getDeptName() {
return deptName;
}
public void setDeptName(String deptName) {
this.deptName = deptName;
}
public Dept() {
}
public Dept(int deptId, String deptName) {
this.deptId = deptId;
this.deptName = deptName;
}
@Override
public String toString() {
return "Dept{" +
"deptId=" + deptId +
", deptName='" + deptName + '\'' +
'}';
}
}
```
```java
package bean;
public class Emp {
private int empId;
private String empName;
private String sex;
private int age;
private String tel;
private String passWord;
private int deptId;
private String deptName;
public Emp(int empId) {
}
public int getEmpId() {
return empId;
}
public void setEmpId(int empId) {
this.empId = empId;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getPassWord() {
return passWord;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
public int getDeptId() {
return deptId;
}
public void setDeptId(int deptId) {
this.deptId = deptId;
}
public String getDeptName() {
return deptName;
}
public void setDeptName(String deptName) {
this.deptName = deptName;
}
public Emp() {
}
public Emp(int empId, String empName, String sex, int age, String tel, String passWord, int deptId, String deptName) {
this.empId = empId;
this.empName = empName;
this.sex = sex;
this.age = age;
this.tel = tel;
this.passWord = passWord;
this.deptId = deptId;
this.deptName = deptName;
}
@Override
public String toString() {
return "Emp{" +
"empId=" + empId +
", empName='" + empName + '\'' +
", sex='" + sex + '\'' +
", age=" + age +
", tel='" + tel + '\'' +
", passWord='" + passWord + '\'' +
", deptId=" + deptId +
", deptName='" + deptName + '\'' +
'}';
}
}
```
```java
package servlet;
import bean.Dept;
import bean.Emp;
import util.DBUtil;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
@WebServlet("/add")
public class Add extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String sql="select * from Dept";
ResultSet rst = DBUtil.query(sql);
ArrayList<Dept> list = new ArrayList<>();
try {
while (rst.next()) {
int deptId = rst.getInt("deptId");
String deptName = rst.getString("deptName");
Dept dept = new Dept(deptId, deptName);
list.add(dept);
}
} catch (SQLException e) {
e.printStackTrace();
}
request.setAttribute("list",list);
request.getRequestDispatcher("/WEB-INF/add.jsp").forward(request,response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
```
```java
package servlet;
import bean.Dept;
import bean.Emp;
import util.DBUtil;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
@WebServlet("/delete")
public class Delete extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String sql="select * from Emp";
ResultSet rst = DBUtil.query(sql);
ArrayList<Emp> list = new ArrayList<>();
try {
while (rst.next()) {
int empId = rst.getInt("empId");
Emp emp = new Emp(empId);
list.add(emp);
}
} catch (SQLException e) {
e.printStackTrace();
}
request.setAttribute("list",list);
request.getRequestDispatcher("/WEB-INF/delete.jsp").forward(request,response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
String sql="delete from Emp where EmpID=?";
int empId = Integer.parseInt(request.getParameter("empId"));
int i = DBUtil.update(sql, empId);
if(i>0){
request.setAttribute("msg","删除成功!");
response.sendRedirect("/list");
}else{
request.setAttribute("msg","删除失败!");
request.getRequestDispatcher("/WEB-INF/msg.jsp").forward(request,response);
}
}
}
```
```java
package servlet;
import bean.Emp;
import util.DBUtil;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
@WebServlet("/list")
public class List extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String sql="select * from Dept d,Emp e where d.DeptID=e.DeptID";
ResultSet rst = DBUtil.query(sql);
ArrayList<Emp> list = new ArrayList<>
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
本项目是一个基于Java的JSP+Servlet动态网站开发设计,包含488个文件,主要文件类型包括Markdown文档、Java源代码、JAR包、文本文件、JSP页面、XML配置文件等。系统设计简洁高效,适用于需要进行动态页面交互和数据处理的网站开发。
资源推荐
资源详情
资源评论
收起资源包目录
基于Java的JSP+Servlet动态网站开发设计源码 (489个子文件)
House_info.class 3KB
House_info.class 3KB
Emp.class 3KB
Emp.class 3KB
DBUtil.class 3KB
DBUtil.class 3KB
DBUtil.class 3KB
DBUtil.class 3KB
List.class 3KB
List.class 3KB
list.class 3KB
list.class 3KB
Dept.class 1KB
Dept.class 1KB
House_type.class 1KB
House_type.class 1KB
.gitignore 182B
.gitignore 182B
html.html 123B
untitled8.iml 867B
student.iml 867B
untitled7.iml 867B
mysql-connector-java-5.1.48.jar 983KB
mysql-connector-java-5.1.48.jar 983KB
mysql-connector-java-5.1.48.jar 983KB
mysql-connector-java-5.1.48.jar 983KB
mysql-connector-java-5.1.48.jar 983KB
mysql-connector-java-5.1.8.jar 707KB
mysql-connector-java-5.1.8.jar 707KB
mysql-connector-java-5.1.8.jar 707KB
mysql-connector-java-5.1.8.jar 707KB
standard.jar 384KB
standard.jar 384KB
standard.jar 384KB
standard.jar 384KB
standard.jar 384KB
standard.jar 384KB
standard.jar 384KB
servlet-api.jar 244KB
servlet-api.jar 244KB
servlet-api.jar 244KB
servlet-api.jar 244KB
servlet-api.jar 244KB
servlet-api.jar 244KB
servlet-api.jar 244KB
servlet-api.jar 244KB
servlet-api.jar 244KB
jstl.jar 20KB
jstl.jar 20KB
jstl.jar 20KB
jstl.jar 20KB
jstl.jar 20KB
jstl.jar 20KB
jstl.jar 20KB
DB.java 3KB
Select.java 3KB
DBUtil.java 3KB
House_info.java 2KB
Emp.java 2KB
insert.java 2KB
DBUtil.java 2KB
Emp.java 2KB
DBUtil.java 2KB
HouseInfo.java 2KB
add.java 2KB
select.java 2KB
Select.java 2KB
DanSelect.java 2KB
Insert.java 2KB
insert.java 2KB
list.java 2KB
List.java 2KB
DBUtil.java 2KB
update.java 1KB
DBUtil.java 1KB
xuesheng.java 1KB
updateById.java 1KB
Add.java 1KB
Add.java 1KB
Servletupdate.java 1KB
Delete.java 1KB
DBUtil.java 1KB
delete.java 1KB
saveUpdate.java 1KB
Att.java 1KB
add.java 1KB
deleteById.java 1KB
Student.java 856B
Dept.java 716B
Dept.java 691B
Student.java 665B
Update.java 665B
HouseType.java 640B
House_type.java 639B
Student.java 573B
list.jsp 2KB
add.jsp 1KB
tianjia.jsp 1KB
index.jsp 1KB
index.jsp 1KB
共 489 条
- 1
- 2
- 3
- 4
- 5
资源评论
沐知全栈开发
- 粉丝: 5706
- 资源: 5205
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Python 版官方 Dropbox API V2 SDK.zip
- solidworks焊件槽钢多配置库,一个文件包含所有配置,可用于结构系统,2016以上版本可以打开使用
- jenkins2.346.1最后一版支持java8的jenkins插件
- gcc和clang编译选项总结
- CATICS3D1-18届图纸练习三维二维造型学习建模素材
- CaTICs网络3D大赛-1~8届所有题目建模模型(prt文件)-个人建模,UG8.0以上版本可以打开 观看建模步骤
- linux内核编码风格总结
- 图像识别技术在智能安防、零售、医疗与自动驾驶领域的深度学习应用与实现
- 基于JavaWeb的学生社团信息管理系统源码+数据库脚本.zip
- Python-图片去重工具
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功