最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jdbc+jsp實現(xiàn)簡單員工管理系統(tǒng)

 更新時間:2020年10月29日 13:52:37   作者:lxh5431  
這篇文章主要為大家詳細(xì)介紹了jdbc+jsp實現(xiàn)簡單員工管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

簡單的頁面分析

在上一個文章簡單的數(shù)據(jù)庫連接測試,已經(jīng)測試和數(shù)據(jù)庫做簡單的交互,也就是dao層的實現(xiàn),接下來要說的卻是action的簡單實現(xiàn),在ssh中有struts作為表示層和server的交換,而這里我不是說的是關(guān)于struts這里只是簡單的運用jsp的代碼書寫來實現(xiàn)數(shù)據(jù)的傳輸,這也是最繁瑣的步驟,但是這卻讓我們對底層的調(diào)用有一個簡單的了解,這里是直接調(diào)用封裝好的數(shù)據(jù),交換和使用,首先要書寫的是action的使用,用的最多的就是getParameter表單的提交了,這里在網(wǎng)絡(luò)上提交一個表單嗎,然后通過getParameter進(jìn)行獲取,然后通過enployeeDao中的方法進(jìn)行增刪改查,就能夠進(jìn)行基本的邏輯操作了。

代碼實現(xiàn)

<%@page import="dao.EmployeeDao"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="entity.Employee"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
 pageEncoding="utf-8"%>
<!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>
<body>

 <%
  //1、接收表單提交的參數(shù)
  String action = request.getParameter("action");

  //3.調(diào)用EmployeeDao中addEmployee(Employee employee)完成員工添加
  EmployeeDao employeeDao = new EmployeeDao();
  if (action.equals("0") || action.equals("1")) {
   //添加 更新
   String empno = request.getParameter("empno");
   String ename = request.getParameter("ename");
   String sal = request.getParameter("sal");
   String hiredate = request.getParameter("hiredate");

   //2.將數(shù)據(jù)封裝至Employee對象中
   Employee employee = new Employee();
   employee.setEmpno(Integer.parseInt(empno));
   employee.setEname(ename);
   employee.setSal(Double.parseDouble(sal));
   SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
   employee.setHiredate(sdf.parse(hiredate));

   if (action.equals("0")) {
    //添加
    employeeDao.addEmployee(employee);
   } else {
    //更新
    employeeDao.updateEmployee(employee);
   }

  } else if (action.equals("2")) {
   //刪除
   String empno = request.getParameter("empno");
   employeeDao.deleteEmployee(empno);
  } else if (action.equals("3")) {
   //批量刪除
   System.out.println("action="+action);

   String[] chks=request.getParameterValues("chks");
   for(String chk:chks){
    System.out.println("chk="+chk);
   }


  }

  //4.畫面跳轉(zhuǎn)至employeeList.jsp 重定向
  response.sendRedirect("employeeList.jsp");
 %>
</body>
</html>

然后我們進(jìn)行簡單的頁面設(shè)計,運用了表格的形式進(jìn)行設(shè)計,代碼如下

<%@page import="java.util.List"%>
<%@page import="entity.Employee"%>
<%@page import="dao.EmployeeDao"%>
<%@page language="java" contentType="text/html; charset=utf-8"
 pageEncoding="utf-8"%>
<!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>
<script>
 function checkAll() {

  //1.獲取chkAll的選中狀態(tài)checked
  var chkAll = document.getElementById("chkAll");
  //alert(chkAll.checked);

  //2、獲取其他所有的checkbox
  var chks = document.getElementsByName("chks");
  for (var i = 0; i < chks.length; i++) {
   //3、將chkAll的選中狀態(tài)于其他checkbox的選中狀態(tài)同步
   chks[i].checked = chkAll.checked;
  }
 }

 function onDelete(empno){
  var result=confirm("Delete Employee?");
  if(result){
   window.location.href="employeeManageAction.jsp?action=2&empno=" rel="external nofollow" +empno;
  }
 }

 //function onDeleteBatch(){
  //判斷是否有選中的checkbox

  //有選中的場合
  //提示是否刪除確認(rèn)的信息
  //確認(rèn)刪除
  //提交表單
  //var action=document.getElementById("action");
  //action.value="3";

 // document.frmlist.action="employeeManageAction.jsp"
  // document.frmlist.submit();
  //取消刪除
  //不用處理



  //無選中的場合
  //提示選中記錄的信息

 //}


</script>
</head>
<body>
 <h3>Employee List Page</h3>

 <form name="frmSearch" action="xxxxAction.jsp" method="post">
  ename:<input type="text" /> <input type="submit" name="btnSubmit"
   value="submit" />
 </form>
 <P>
 <hr />

 <a href="employeeManage.jsp?action=0" rel="external nofollow" >Add Employee</a> 
 <a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" onclick="onDeleteBatch();">Delete
  Employee Batch</a>
 <P>
  <%
   EmployeeDao emplyeeDao = new EmployeeDao();
   List<Employee> employees = emplyeeDao.getEmployees();
  %>

  <%
   if (employees != null && employees.size() > 0) {
  %>

 <form name="frmlist" action="" method="post">
  <input type="hidden" name="action" id="action" value="" />
  <table width="600px" border="1px">

   <tr bgcolor="#009966">
    <td><input type="checkbox" id="chkAll" onclick="checkAll()" /></td>
    <td>empno</td>
    <td>ename</td>
    <td>sal</td>
    <td>hiredate</td>
    <td>action</td>
   </tr>

   <%
    Employee employee = null;
     for (int i = 0; i < employees.size(); i++) {
      employee = employees.get(i);
   %>
   <tr>
    <td><input type="checkbox" id="chk<%=i + 1%>" name="chks"
     value="<%=employee.getEmpno()%>" /></td>
    <td><%=employee.getEmpno()%></td>
    <td><%=employee.getEname()%></td>
    <td><%=employee.getSal()%></td>
    <td><%=employee.getHiredate()%></td>
    <td><a
     href="employeeManage.jsp?action=1&empno=<%=employee.getEmpno()%>" rel="external nofollow" >update</a>
     <a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" 
     onclick="onDelete(<%=employee.getEmpno()%>);">delete</a></td>
   </tr>
   <%
    }
   %>
  </table>

 </form>

 <%
  }
 %>
</body>
</html>

接下來要說的是更新操作

<%@page import="entity.Employee"%>
<%@page import="dao.EmployeeDao"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
 pageEncoding="utf-8"%>
<!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>
<script>
 function checkForm() {

  var empno = document.getElementById("empno");
  if (empno && empno.value == "") {
   empno.focus();
   alert("please input empno");
   return;
  }

  var ename = document.getElementById("ename");
  if (ename && ename.value == "") {
   ename.focus();
   alert("please input ename");
   return;
  }

  var sal = document.getElementById("sal");
  if (sal && sal.value == "") {
   sal.focus();
   alert("please input sal");
   return;
  }

  var hiredate = document.getElementById("hiredate");
  if (hiredate && hiredate.value == "") {
   hiredate.focus();
   alert("please input hiredate");
   return;
  }

  var frm = document.getElementById("frm");
  frm.submit();

 }
</script>


</head>
<body>

 <%
  String action=request.getParameter("action");

  Employee employee=null;
  if(action.equals("1")){
   //更新操作
   String empno = request.getParameter("empno");

   EmployeeDao employeeDao = new EmployeeDao();
   employee=employeeDao.getEmployeeByEmpno(empno);
  }

 %>

 <h3>Employee <%=action.equals("1")?"Update":"Regist" %> Page</h3>

 <form id="frm" action="employeeManageAction.jsp" method="post"
  onsubmit="return checkForm();">
  <input type="hidden" name="action" value="<%=action%>"/>
  <table>
   <tr>
    <td>empno</td>
    <td><input type="text" id="empno" name="empno" <%=action.equals("1")?"readOnly":"" %> value="<%=employee==null?"":employee.getEmpno()%>"/></td>
   </tr>

   <tr>
    <td>ename</td>
    <td><input type="text" id="ename" name="ename" value="<%=employee==null?"":employee.getEname()%>"/></td>
   </tr>

   <tr>
    <td>sal</td>
    <td><input type="text" id="sal" name="sal" value="<%=employee==null?"":employee.getSal()%>"/></td>
   </tr>

   <tr>
    <td>hiredate</td>
    <td><input type="text" id="hiredate" name="hiredate" value="<%=employee==null?"":employee.getHiredate()%>"/></td>
   </tr>

   <tr>
    <td><input type="button" name="btnSubmit" value="submit"
     onclick="checkForm();" /></td>
    <td><input type="reset" name="btnReset" value="reset" /></td>
   </tr>
  </table>
 </form>
</body>
</html>

在這個過程中剛好用到了簡單的js對數(shù)據(jù)進(jìn)行非空和數(shù)據(jù)類型判斷,這就是我們需要學(xué)會的邏輯,業(yè)務(wù)層,然后進(jìn)行其他操作,當(dāng)然我注釋的是還沒完成的多個刪除和模糊搜索,這個下一個博客再去完善。

總結(jié)

在學(xué)習(xí)這個過程中,學(xué)會了更多關(guān)于數(shù)據(jù)調(diào)用的知識,而不是像hibernate那樣在配置文件配置,然后直接調(diào)用就可以了,再用jsp中也發(fā)現(xiàn)jsp嵌入代碼,更加笨重,這也是我學(xué)習(xí)的另一個方面吧。

更多學(xué)習(xí)資料請關(guān)注專題《管理系統(tǒng)開發(fā)》。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 淺談SpringBoot 中關(guān)于自定義異常處理的套路

    淺談SpringBoot 中關(guān)于自定義異常處理的套路

    這篇文章主要介紹了淺談SpringBoot 中關(guān)于自定義異常處理的套路,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • IDEA類和方法注釋模板設(shè)置(非常詳細(xì))

    IDEA類和方法注釋模板設(shè)置(非常詳細(xì))

    這篇文章主要介紹了IDEA類和方法注釋模板設(shè)置(非常詳細(xì)),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-08-08
  • springboot配置resilience4j全過程

    springboot配置resilience4j全過程

    這篇文章主要介紹了springboot配置resilience4j全過程,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-05-05
  • 關(guān)于shiro中部分SpringCache失效問題的解決方法

    關(guān)于shiro中部分SpringCache失效問題的解決方法

    這篇文章主要給大家介紹了關(guān)于shiro中部分SpringCache失效問題的解決方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-07-07
  • springmvc處理模型數(shù)據(jù)ModelAndView過程詳解

    springmvc處理模型數(shù)據(jù)ModelAndView過程詳解

    這篇文章主要介紹了springmvc處理模型數(shù)據(jù)ModelAndView過程詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-01-01
  • Spring MVC中處理ajax請求的跨域問題與注意事項詳解

    Spring MVC中處理ajax請求的跨域問題與注意事項詳解

    跨域問題是我們大家在開發(fā)中會經(jīng)常遇到的一個問題,所以下面這篇文章主要給大家介紹了關(guān)于Spring MVC中處理ajax請求的跨域問題與注意事項的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-11-11
  • springboot中使用FastJson解決long類型在js中失去精度的問題

    springboot中使用FastJson解決long類型在js中失去精度的問題

    這篇文章主要介紹了springboot中使用FastJson解決long類型在js中失去精度的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • Spring data JPA只查詢部分字段問題及解決

    Spring data JPA只查詢部分字段問題及解決

    這篇文章主要介紹了Spring data JPA只查詢部分字段問題及解決,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • Java中的cglib代理詳解

    Java中的cglib代理詳解

    這篇文章主要介紹了Java中的cglib代理詳解, 代理模式是一種設(shè)計模式,它可以為其他對象提供一種代理,以控制對該對象的訪問,可以在運行時動態(tài)地創(chuàng)建代理對象,而不需要手動編寫代理類的代碼,需要的朋友可以參考下
    2023-09-09
  • Eclipse?Jetty?server漏洞解決辦法

    Eclipse?Jetty?server漏洞解決辦法

    最近給?個客戶部署項?,但是客戶的安全稽核有點變態(tài),居然說 Eclipse Jetty Server?危漏洞,這篇文章主要給大家介紹了關(guān)于Eclipse?Jetty?server漏洞解決的相關(guān)資料,需要的朋友可以參考下
    2023-11-11

最新評論

鄂伦春自治旗| 大港区| 泽州县| 密山市| 札达县| 集安市| 筠连县| 刚察县| 盖州市| 奉新县| 景德镇市| 恩施市| 奉化市| 建德市| 文登市| 乡城县| 宁强县| 江川县| 望谟县| 洪江市| 泗水县| 美姑县| 淅川县| 永靖县| 枣庄市| 滨海县| 富平县| 井冈山市| 永春县| 虎林市| 日喀则市| 公安县| 丹阳市| 丰原市| 普兰店市| 玉门市| 准格尔旗| 曲水县| 巴里| 漯河市| 靖西县|