Java web项目:休假申请管理系统,合并表格的行或列,JS获取下拉框的值【诗书画唱】















create table FURLOUGHAPPLY(
ID int primary key auto_increment,
PROPOSER varchar(100) not null,
DEPT varchar(100) not null,
APPLYDATE date not null,
STARTTIME date not null,
LASTTIME date not null,
TYPE varchar(30) not null);
insert into FURLOUGHAPPLY(
PROPOSER,
DEPT,
APPLYDATE,
STARTTIME,
LASTTIME,
TYPE
) values ("诗书画唱1",'财务部','2020-01-06','2012-01-07 08:30','2020-01-09 17:30','事假'),
("诗书画唱2",'设计部','2020-01-07','2012-01-07 08:30','2020-01-10 17:30','病假'),
("诗书画唱3",'市场部','2020-01-08','2012-01-07 08:30','2020-01-11 17:30','事假'),
("诗书画唱4",'市场部','2020-01-09','2012-01-07 08:30','2020-01-12 17:30','婚假');
--drop table FURLOUGHAPPLY
--select * from FURLOUGHAPPLY




package com.SSHC.bean;
import java.util.Date;
public class FURLOUGHAPPLY {
private Integer ID ;
private String PROPOSER ;
private String DEPT ;
private String APPLYDATE;
private String STARTTIME;
private String LASTTIME;
private String TYPE;
public Integer getID() {
return ID;
}
public void setID(Integer iD) {
ID = iD;
}
public String getPROPOSER() {
return PROPOSER;
}
public void setPROPOSER(String pROPOSER) {
PROPOSER = pROPOSER;
}
public String getDEPT() {
return DEPT;
}
public void setDEPT(String dEPT) {
DEPT = dEPT;
}
public String getAPPLYDATE() {
return APPLYDATE;
}
public void setAPPLYDATE(String aPPLYDATE) {
APPLYDATE = aPPLYDATE;
}
public String getSTARTTIME() {
return STARTTIME;
}
public void setSTARTTIME(String sTARTTIME) {
STARTTIME = sTARTTIME;
}
public String getLASTTIME() {
return LASTTIME;
}
public void setLASTTIME(String lASTTIME) {
LASTTIME = lASTTIME;
}
public String getTYPE() {
return TYPE;
}
public void setTYPE(String tYPE) {
TYPE = tYPE;
}
}


package com.SSHC.controller;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.SSHC.DAO.Dao;
import com.SSHC.bean.FURLOUGHAPPLY;
/**
* Servlet implementation class addOKServlet
*/
@WebServlet("/AddServlet")
public class AddServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public AddServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest
* request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
this.doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest
* request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest
request, HttpServletResponse response)
throws ServletException, IOException {
//String ID = request.getParameter("ID");
//
//
//Integer ID2=0;
//if(ID!=null){
//
// ID2=Integer.parseInt(ID);
//}
String APPLYDATE= request.getParameter("APPLYDATE");
String DEPT= request.getParameter("DEPT");
String STARTTIME= request.getParameter("STARTTIME");
String LASTTIME= request.getParameter("LASTTIME");
String PROPOSER= request.getParameter("PROPOSER");
String TYPE= request.getParameter("TYPE");
System.out.println(PROPOSER);
FURLOUGHAPPLY u = new FURLOUGHAPPLY();
//u.setID(ID2);
u.setAPPLYDATE(APPLYDATE);
u.setDEPT(DEPT);
u.setLASTTIME(LASTTIME);
u.setPROPOSER(PROPOSER);
u.setTYPE(TYPE);
u.setSTARTTIME(STARTTIME);
//
Dao ud = new Dao();
ud.add(u);
//个人想出来的注释: 下面注释部分的代码不可以判断是否添加成功:
// List<FURLOUGHAPPLY> List=ud.selectOne(u.getID());
// String S=null;
// System.out.println(List.size());
//if(List.size()>0){
// S="申请成功!";
//}
//
//else {
// S="申请失败!";
// }request.setAttribute("S", S);
//
// request.getRequestDispatcher("addOK.jsp")
// .forward(request, response);
// for (FURLOUGHAPPLY furloughapPLY : List) {
// System.out.println(furloughapPLY);
// }
String S=null;
//个人想出来的注释: 下面注释部分的代码不可以判断是否添加成功:
//if(u.getID()!=null&&u.getAPPLYDATE()!=null
//&&u.getDEPT()!=null&&u.getPROPOSER()!=null
//&&u.getTYPE()!=null&&u.getSTARTTIME()!=null){
System.out.println("数据库更新的条数为:"+ud.count+"条");
if(ud.count>0){
S="申请成功!";
}else {
S="申请失败!";
}request.setAttribute("S", S);
request.getRequestDispatcher("addOK.jsp")
.forward(request, response);
}
}


package com.SSHC.controller;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.SSHC.DAO.Dao;
import com.SSHC.bean.FURLOUGHAPPLY;
@WebServlet("/FirstPageServletStart")
public class FirstPageServletStart extends HttpServlet {
private static final long serialVersionUID = 1L;
public FirstPageServletStart() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request,
* HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
this.doPost(request, response);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
Dao gd = new Dao();
List<FURLOUGHAPPLY>list = gd.selectAll();
StringBuilder html = new StringBuilder();
for(FURLOUGHAPPLY g : list) {
Integer ID= g.getID();
String PROPOSER= g.getPROPOSER();
String DEPT= g.getDEPT();
String APPLYDATE= g.getAPPLYDATE();
String STARTTIME= g.getSTARTTIME();
String LASTTIME= g.getLASTTIME();
String TYPE= g.getTYPE();
System.out.println(PROPOSER);
html.append("<tr class='two'>");
html.append("<td >" + PROPOSER + "</td>");
html.append("<td >" + DEPT + "</td>");
html.append("<td >" + APPLYDATE + "</td>");
html.append("<td >" + STARTTIME + "</td>");
html.append("<td >" + LASTTIME+ "</td>");
html.append("<td >" + TYPE+ "</td>");
html.append("</tr>");
}
request.setAttribute("html", html);
System.out.println(html);
request.getRequestDispatcher("firstPage.jsp")
.forward(request, response);
}
}


package com.SSHC.DAO;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.SSHC.bean.FURLOUGHAPPLY;
import com.SSHC.utils.DBUtils;
public class Dao {
public List<FURLOUGHAPPLY>selectOne(Integer Oid){
String sql = "select * from FURLOUGHAPPLY where ID=?";
Connection conn = null;
PreparedStatement pstm = null;
ResultSet rs = null;
List<FURLOUGHAPPLY>list = new ArrayList<FURLOUGHAPPLY>();
try {
conn = DBUtils.getConn();
pstm = conn.prepareStatement(sql);
pstm.setObject(1, Oid);
System.out.println(sql);
rs = pstm.executeQuery();
while(rs.next()) {
Integer ID = rs.getInt("ID");
String APPLYDATE= rs.getString("APPLYDATE");
String DEPT = rs.getString("DEPT");
String LASTTIME= rs.getString("LASTTIME");
String PROPOSER= rs.getString("PROPOSER");
String TYPE = rs.getString("TYPE");
String STARTTIME= rs.getString("STARTTIME");
System.out.println(LASTTIME);
//进行打包:
FURLOUGHAPPLY g = new FURLOUGHAPPLY();
g.setID(ID);
g.setAPPLYDATE(APPLYDATE);
g.setDEPT(DEPT);
g.setLASTTIME(LASTTIME);
g.setPROPOSER(PROPOSER);
g.setTYPE(TYPE);
g.setSTARTTIME(STARTTIME);
//继续打包:
list.add(g);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
public List<FURLOUGHAPPLY>selectAll(){
String sql = "select * from FURLOUGHAPPLY order by APPLYDATE desc";
Connection conn = null;
PreparedStatement pstm = null;
ResultSet rs = null;
List<FURLOUGHAPPLY>list = new ArrayList<FURLOUGHAPPLY>();
try {
conn = DBUtils.getConn();
pstm = conn.prepareStatement(sql);
rs = pstm.executeQuery();
while(rs.next()) {
Integer ID = rs.getInt("ID");
String APPLYDATE= rs.getString("APPLYDATE");
String DEPT = rs.getString("DEPT");
String LASTTIME= rs.getString("LASTTIME");
String PROPOSER= rs.getString("PROPOSER");
String TYPE = rs.getString("TYPE");
String STARTTIME= rs.getString("STARTTIME");
System.out.println(LASTTIME);
//进行打包:
FURLOUGHAPPLY g = new FURLOUGHAPPLY();
g.setID(ID);
g.setAPPLYDATE(APPLYDATE);
g.setDEPT(DEPT);
g.setLASTTIME(LASTTIME);
g.setPROPOSER(PROPOSER);
g.setTYPE(TYPE);
g.setSTARTTIME(STARTTIME);
//继续打包:
list.add(g);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
//声明为public的全局变量才可以在AddServlet中靠Dao.count获取count
public int count=0;
//我尝试,测试过了 public static int count=0;也可以
public Integer add(FURLOUGHAPPLY u) {
String sql = "insert into FURLOUGHAPPLY("
+ "PROPOSER,DEPT,APPLYDATE,STARTTIME,"
+ "LASTTIME, TYPE ) values (?,?,?,?,?,?);";
Connection conn = null;
PreparedStatement pstm = null;
ResultSet rs = null;
try {
conn = DBUtils.getConn();
pstm = conn.prepareStatement(sql);
pstm.setObject(1,u.getPROPOSER());
pstm.setObject(2,u.getDEPT() );
pstm.setObject(3,u.getAPPLYDATE());
pstm.setObject(4,u.getSTARTTIME());
pstm.setObject(5,u.getLASTTIME() );
pstm.setObject(6,u.getTYPE());
count=pstm.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
DBUtils.close(rs, pstm, conn);
}
return 0;
}
}


package com.SSHC.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;
import javax.servlet.annotation.WebFilter;
@WebFilter("/*")
public class CodeFilter implements Filter {
public CodeFilter() {
// TODO Auto-generated constructor stub
}
public void destroy() {
// TODO Auto-generated method stub
}
public void doFilter(ServletRequest request,
ServletResponse response, FilterChain chain)
throws IOException, ServletException {
// TODO Auto-generated method stub
// place your code here
request.setCharacterEncoding("utf-8");
chain.doFilter(request, response);
}
public void init(FilterConfig fConfig) throws ServletException {
// TODO Auto-generated method stub
}
}


package com.SSHC.utils;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;
public class DBUtils {
private static String driverName;
private static String url;
private static String userName;
private static String pwd;
//静态块,随着类加载而运行的
static{
//读取db.properties文件中的内容
Properties prop = new Properties();
InputStream is = DBUtils.class.getClassLoader()
.getResourceAsStream("db.properties");
try {
prop.load(is);
driverName = prop.getProperty("dn");
url = prop.getProperty("url");
userName = prop.getProperty("un");
pwd = prop.getProperty("up");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static Connection getConn(){
Connection conn = null;
try {
Class.forName(driverName);
conn = DriverManager.getConnection(url,userName,pwd);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
public static void close(ResultSet rs,PreparedStatement pstm
,Connection conn){
try {
if(rs != null) {
rs.close();
}
if(pstm != null) {
pstm.close();
}
if(conn != null) {
conn.close();
}
} catch(Exception e) {
e.printStackTrace();
}
}
}



dn=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/studentdb?useUnicode=true&characterEncoding=UTF-8
un=root
up=root




<%@ page language="java" contentType=
"text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()
+"://"+request.getServerName()
+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base hreff="<%=basePath%>">
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<style type="text/css">
* {
opacity:0.95;
}
<%-- tr:nth-of-type(even){ background:white; }--%>
<%--偶数行:--%>
<%--tr:nth-of-type(odd){ background: gray;}--%>
.one{ font-size: 30px;}
.two{ font-size: 23px;}
input{font-size: 23px;}
select{font-size: 23px;}
body{
background-image: url('img/china.jpg');
background-repeat: no-repeat;
background-size: 100%;
}
</style>
<script type="text/javascript">
function cancel(){
window.location.href = 'add.jsp';
}
function doCheck(){
var selectDEPT=document.getElementById("DEPTId").value
var selectTYPE=document.getElementById("TYPEId").value
var PROPOSER= document.getElementsByName('PROPOSER')[0].value;
var APPLYDATE= document.getElementsByName('APPLYDATE')[0].value;
var STARTTIME= document.getElementsByName('STARTTIME')[0].value;
var LASTTIME=document.getElementsByName('LASTTIME')[0].value;
var reg = /.{1,}/;
var VPROPOSER= reg.test(PROPOSER);
var VAPPLYDATE= reg.test(APPLYDATE);
var VSTARTTIME= reg.test(STARTTIME);
var VLASTTIME= reg.test(LASTTIME);
var VselectDEPT= reg.test(selectDEPT);
var VselectTYPE= reg.test(selectTYPE);
if(!VselectDEPT) {
alert('部门框不能为空!');
return VselectDEPT;
} if(!VselectTYPE) {
alert('休假类型框不能为空!');
return VselectTYPE;
}
if(!VPROPOSER) {
alert('申请人框不能为空!');
return VPROPOSER;
}
if(!VAPPLYDATE) {
alert('申请日期框不能为空!');
return VAPPLYDATE;
}
if(!VSTARTTIME) {
alert('开始日期及时间框不能为空!');
return VSTARTTIME;
}
if(!VLASTTIME) {
alert('结束时间及日期框不能为空!');
return VLASTTIME;
}
}
</script>
</head>
<body>
<table style="width:100%;" >
<tr class='one'>
<td style="background-color:gray;text-align:center;">提交申请</td>
</tr>
<tr>
<td align="center">
<%-- onsubmit事件在表单提交时触发。 --%>
<form action="AddServlet" method="post"
onsubmit="return doCheck();">
<table>
<%-- <tr>
<td>【隐藏框】编号:</td>
<td>
<input type="hidden" name="ID" />
</td>
</tr>--%>
<tr class='two'>
<td>申请人:</td>
<td>
<input type="text" name="PROPOSER" />
</td>
</tr>
<tr class='two'>
<td>部门:</td>
<td>
<select id='DEPTId' name="DEPT" >
<option value='' selected>请选择</option>
<option value='人事部' >人事部</option>
<option value='财务部' >财务部</option>
<option value='市场部' >市场部</option>
<option value='设计部' >设计部</option>
</select></td>
</tr>
<tr class='two'>
<td>申请日期:</td>
<td><input type="text" name="APPLYDATE" />
<span style="color:red;"> 如:yyyy-mm-dd</span></td>
</tr>
<tr class='two'>
<td>开始日期及时间:</td>
<td><input type="text" name="STARTTIME" />
<span style="color:red;"> 如: yyyy-mm-dd hh:MM</span></td>
</tr>
<tr class='two'>
<td>结束时间及日期:</td>
<td><input type="text" name="LASTTIME" />
<span style="color:red;">如:yyyy-mm-dd hh:MM</span></td>
</tr>
<tr class='two'>
<td>休假类型:</td>
<td>
<select id='TYPEId' name="TYPE">
<option value='' selected>请选择</option>
<option value='病假' >病假</option>
<option value='事假' >事假</option>
<option value='婚假' >婚假</option>
<option value='丧假' >丧假</option>
</select></td>
</tr>
<tr class='two'>
<td colspan="2" align="center">
<input type="submit" value="申请" onclick='doCheck();' />
<input type="button" value="重置" onclick="cancel();" />
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>


<%@ page language="java" contentType=
"text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@page import="com.SSHC.DAO.Dao"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<script type="text/javascript">
alert('${S }');
</script>
<body>
<%-- request.getRequestDispatcher("firstPage.jsp")
.forward(request, response);--%>
</body>
</html>


<%@ page language="java" contentType="text/html;
charset=UTF-8" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()
+"://"+request.getServerName()
+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base hreff="<%=basePath%>">
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<style type="text/css">
* {
opacity:0.95;
}
td{text-align: center;vertical-align: middle;}
<%--奇数行:--%>
tr:nth-of-type(even){ background:white; }
<%--偶数行:--%>
.one{ font-size: 30px;}
.two{ font-size: 23px;}
tr:nth-of-type(odd){ background: gray;}
body{
background-image: url('img/china.jpg');
background-repeat: no-repeat;
background-size: 100%;
}
</style>
<script type="text/javascript">
function bk(){
window.location.hreff = 'add.jsp';
}
</script>
</head>
<body>
<table cellspacing="0px" border="1px" style="width:100%;">
<tr class="one">
<td style="background-color:gray;
text-align:center;"
colspan='6'>休假申请信息</td>
</tr>
<tr class="two">
<th >申请人</th>
<th>部门</th>
<th >申请日期</th>
<th>开始日期及时间</th>
<th >结束日期及时间</th>
<th>休假类型</th>
</tr>
${html }
<tr class="two"> <td colspan='6'><a hreff="javascript:bk()"
style="float:right;" >申请</a></td></tr>
</table>
</body>
</html>









