一、实验介绍

1.1 实验内容

本节课程主要利用 easyUI 实现系统的前端页面。

1.2 实验知识点

  • easyUI
  • JavaScript
  • html

1.3 实验环境

  • JDK1.8
  • Eclipse JavaEE

二、实验步骤

2.1 表现层相关文件获取

打开终端,输入以下命令获取相关文件,包括 easyui、jQuery 等相关文件,保存到目录 /home/shiyanlou/ 下。

  1. wget http://labfile.oss.aliyuncs.com/courses/824/fontendFiles.tar

解压文件到 /home/shiyanlou/ 下。

  1. tar zxvf fontendFiles.tar

然后将 /home/shiyanlou/fontendFiles 文件夹下的全部文件夹拷贝到项目 hrmssrc->main->webapp 下。

2.2 login.jsp

在项目 hrmssrc->main->webapp 下新建 JSP 页面 login.jsp 作为系统的登录页面,并添加如下代码:

  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//Dtd HTML 4.01 Transitional//EN">
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. <title>hrms-login</title>
  8. <script type="text/javascript"
  9. src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
  10. <style type=text/css>
  11. body {
  12. text-align: center;
  13. padding-bottom: 0px;
  14. background-color: #ddeef2;
  15. margin: 0px;
  16. padding-left: 0px;
  17. padding-right: 0px;
  18. padding-top: 0px
  19. }
  20. A:link {
  21. COLOR: #000000;
  22. text-decoration: none
  23. }
  24. A:visited {
  25. COLOR: #000000;
  26. text-decoration: none
  27. }
  28. A:hover {
  29. COLOR: #ff0000;
  30. text-decoration: underline
  31. }
  32. A:active {
  33. text-decoration: none
  34. }
  35. .input {
  36. border-bottom: #ccc 1px solid;
  37. border-left: #ccc 1px solid;
  38. line-height: 20px;
  39. width: 182px;
  40. height: 20px;
  41. border-top: #ccc 1px solid;
  42. border-right: #ccc 1px solid
  43. }
  44. .input1 {
  45. border-bottom: #ccc 1px solid;
  46. border-left: #ccc 1px solid;
  47. line-height: 20px;
  48. width: 120px;
  49. height: 20px;
  50. border-top: #ccc 1px solid;
  51. border-right: #ccc 1px solid;
  52. }
  53. </style>
  54. <script type="text/javascript">
  55. /* 登录 */
  56. function login() {
  57. var username = $("#username").val();
  58. var password = $("#password").val();
  59. if (username == null || username == "") {
  60. alert("username can't be empty\uff01");
  61. return;
  62. }
  63. if (password == null || password == "") {
  64. alert("password can't be empty\uff01");
  65. return;
  66. }
  67. $("#adminlogin").submit();
  68. }
  69. /* 用户名或密码错误时显示 */
  70. if ('${errorMsg}' != '') {
  71. alert('${errorMsg}');
  72. }
  73. /* 拦截器显示信息 */
  74. if ('${message}' != '') {
  75. alert('${message}');
  76. }
  77. </script>
  78. </head>
  79. <body>
  80. <form id=adminlogin method=post name=adminlogin
  81. action="${pageContext.request.contextPath}/admin/login">
  82. <div></div>
  83. <table style="margin: auto; width: 100%; height: 100%" border=0
  84. cellSpacing=0 cellPadding=0>
  85. <tbody>
  86. <tr>
  87. <td height=150>&nbsp;</td>
  88. </tr>
  89. <tr style="height: 254px">
  90. <td>
  91. <div style="margin: 0px auto; width: 868px">
  92. <img style="display: block"
  93. src="${pageContext.request.contextPath}/images/body_03.jpg">
  94. </div>
  95. <div style="background-color: #278296">
  96. <div style="margin: 0px auto; width: 936px">
  97. <div
  98. style="BACKGROUND: url(${pageContext.request.contextPath}/images/body_05.jpg) no-repeat; height: 155px">
  99. <div
  100. style="text-align: left; width: 265px; float: right; height: 125px; _height: 95px">
  101. <table border=0 cellSpacing=0 cellPadding=0 width="100%">
  102. <tbody>
  103. <tr>
  104. <td style="height: 45px"><input type="text"
  105. class=input value="${admin.username}" name="username"
  106. id="username"></td>
  107. </tr>
  108. <tr>
  109. <td><input type="password" class=input
  110. value="${admin.password}" name="password" id="password" /></td>
  111. </tr>
  112. </tbody>
  113. </table>
  114. </div>
  115. <div style="height: 1px; clear: both"></div>
  116. <div style="width: 380px; float: right; clear: both">
  117. <table border=0 cellSpacing=0 cellPadding=0 width=300>
  118. <tbody>
  119. <tr>
  120. <td width=100 align=right><input
  121. style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px"
  122. id=btnLogin
  123. src="${pageContext.request.contextPath}/images/btn1.jpg"
  124. type=image name=btnLogin onclick="javascript:login();"></td>
  125. <td width=100 align=middle><input
  126. style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px"
  127. id=btnReset
  128. src="${pageContext.request.contextPath}/images/btn2.jpg"
  129. type=image name=btnReset
  130. onclick="javascript:adminlogin.reset();"></td>
  131. </tr>
  132. </tbody>
  133. </table>
  134. </div>
  135. </div>
  136. </div>
  137. </div>
  138. <div style="margin: 0px auto; width: 936px">
  139. <img src="${pageContext.request.contextPath}/images/body_06.jpg">
  140. </div>
  141. </td>
  142. </tr>
  143. <tr style="height: 30%">
  144. <td>&nbsp;</td>
  145. </tr>
  146. </tbody>
  147. </table>
  148. </form>
  149. </body>
  150. </html>

2.3 home_page.jsp

在项目 hrmssrc->main->webapp 下新建 JSP 页面 home_page.jsp 作为系统的主页面,并添加如下代码:

  1. <%@ page language="java" contentType="text/html; charset=utf-8"
  2. pageEncoding="utf-8"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  7. <title>hrms_main</title>
  8. <link rel="stylesheet" type="text/css"
  9. href="${pageContext.request.contextPath}/jquery-easyui-1.3.3/themes/default/easyui.css">
  10. <link rel="stylesheet" type="text/css"
  11. href="${pageContext.request.contextPath}/jquery-easyui-1.3.3/themes/icon.css">
  12. <script type="text/javascript"
  13. src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.min.js"></script>
  14. <script type="text/javascript"
  15. src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
  16. <script type="text/javascript">
  17. var url;
  18. function addTab(url, text, iconCls) {
  19. var content = "<iframe frameborder=0 scrolling='auto' style='width:100%;height:100%' src='${pageContext.request.contextPath}/views/"
  20. + url + "'></iframe>";
  21. $("#tabs").tabs("add", {
  22. title : text,
  23. iconCls : iconCls,
  24. closable : true,
  25. content : content
  26. });
  27. }
  28. function openTab(text, url, iconCls) {
  29. if ($("#tabs").tabs("exists", text)) {
  30. $("#tabs").tabs("close", text);
  31. addTab(url, text, iconCls);
  32. $("#tabs").tabs("select", text);
  33. } else {
  34. addTab(url, text, iconCls);
  35. }
  36. }
  37. /* 退出 */
  38. function logout() {
  39. $.messager
  40. .confirm(
  41. "system prompt",
  42. "Do you want to exit?",
  43. function(r) {
  44. if (r) {
  45. window.location.href = "${pageContext.request.contextPath}/admin/logout";
  46. }
  47. });
  48. }
  49. </script>
  50. <body class="easyui-layout">
  51. <div region="north" style="height: 78px; background-color: #ffff">
  52. <table width="100%">
  53. <tr>
  54. <td width="50%"></td>
  55. <td valign="bottom"
  56. style="font-size: 20px; color: #8B8B8B; font-family: '\u6977\u4f53';"
  57. align="right" width="50%"><font size="3">&nbsp;&nbsp;<strong>Current
  58. Admin\uff1a</strong>
  59. </font> <font color="red">${sessionScope.currentAdmin.username}</font></td>
  60. </tr>
  61. </table>
  62. </div>
  63. <div region="center">
  64. <div class="easyui-tabs" fit="true" border="false" id="tabs">
  65. <div title="Home" data-options="iconCls:'icon-home'">
  66. <div align="center" style="padding-top: 50px">
  67. <font color="grey" size="10">Human Affairs Management System</font>
  68. </div>
  69. <div align="center" style="padding-top: 20px;">
  70. <font style="font-size: 20px;">www.shiyanlou.com</font>
  71. </div>
  72. </div>
  73. </div>
  74. </div>
  75. <div region="west" style="width: 200px; height: 500px;"
  76. title="Navigation Menu" split="true">
  77. <div class="easyui-accordion">
  78. <div title="Department Manage"
  79. data-options="selected:true,iconCls:'icon-shujias'"
  80. style="padding: 10px; height: 10px;">
  81. <a href="javascript:openTab(' Department Info','deptManage.jsp')"
  82. class="easyui-linkbutton" data-options="plain:true"
  83. style="width: 150px;"> Department Info</a>
  84. </div>
  85. <div title="Position Manage"
  86. data-options="selected:true,iconCls:'icon-schoolceo'"
  87. style="padding: 10px; height: 10px;">
  88. <a href="javascript:openTab(' Position Info','positionManage.jsp')"
  89. class="easyui-linkbutton" data-options="plain:true"
  90. style="width: 150px;"> Position Info</a>
  91. </div>
  92. <div title="Employee Manage" data-options="iconCls:'icon-students' "
  93. style="padding: 10px">
  94. <a href="javascript:openTab(' Employee Info','employeeManage.jsp')"
  95. class="easyui-linkbutton" data-options="plain:true"
  96. style="width: 150px;">Employee Info</a>
  97. </div>
  98. <div title="Post Manage"
  99. data-options="selected:true,iconCls:'icon-wenzhang'"
  100. style="padding: 10px; height: 10px;">
  101. <a href="javascript:openTab(' Post Info','postManage.jsp')"
  102. class="easyui-linkbutton" data-options="plain:true"
  103. style="width: 150px;"> Post Info</a>
  104. </div>
  105. <div title="System Manage" data-options="iconCls:'icon-item'"
  106. style="padding: 10px; border: none;">
  107. <a
  108. href="javascript:openTab(' Admin List','adminManage.jsp','icon-lxr')"
  109. class="easyui-linkbutton"
  110. data-options="plain:true,iconCls:'icon-lxr'" style="width: 150px;">
  111. Admin List</a><a href="javascript:logout()" class="easyui-linkbutton"
  112. data-options="plain:true,iconCls:'icon-exit'" style="width: 150px;">
  113. Exit</a>
  114. </div>
  115. </div>
  116. </div>
  117. </body>
  118. </html>

2.4 postContent.jsp

在项目 hrmssrc->main->webapp 下新建 JSP 页面 postContent.jsp 作为公告内容详情的展示页面,并添加如下代码:

  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. <title>Post Content</title>
  8. </head>
  9. <body>${requestScope.postContent}
  10. </body>
  11. </html>

2.5 五大功能模块 JSP 页面

在项目 hrmssrc->main->webapp 下新建 Folder views

2.5.1 adminManage.jsp

在项目 hrmssrc->main->webapp->views 下新建 JSP 页面 adminManage.jsp 作为系统管理页面,并添加如下代码:

  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. <title>Insert title here</title>
  8. <link rel="stylesheet" type="text/css"
  9. href="${pageContext.request.contextPath}/jquery-easyui-1.3.3/themes/default/easyui.css">
  10. <link rel="stylesheet" type="text/css"
  11. href="${pageContext.request.contextPath}/jquery-easyui-1.3.3/themes/icon.css">
  12. <script type="text/javascript"
  13. src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.min.js"></script>
  14. <script type="text/javascript"
  15. src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
  16. <script type="text/javascript">
  17. var url;
  18. /* 根据条件查询管理员 */
  19. function searchAdmin() {
  20. $("#dg").datagrid('load', {
  21. "username" : $("#s_username").val()
  22. });
  23. }
  24. /* 删除管理员,可以是多个 */
  25. function deleteAdmin() {
  26. var selectedRows = $("#dg").datagrid('getSelections');
  27. if (selectedRows.length == 0) {
  28. $.messager.alert("system prompt",
  29. "Please choose the data to delete!");
  30. return;
  31. }
  32. var strIds = [];
  33. for ( var i = 0; i < selectedRows.length; i++) {
  34. strIds.push(selectedRows[i].id);
  35. }
  36. var ids = strIds.join(",");
  37. $.messager
  38. .confirm(
  39. "system prompt",
  40. "Do you want to delete the <font color=red>"
  41. + selectedRows.length + "</font> data?",
  42. function(r) {
  43. if (r) {
  44. $
  45. .post(
  46. "${pageContext.request.contextPath}/admin/delete",
  47. {
  48. ids : ids
  49. },
  50. function(result) {
  51. if (result.success) {
  52. $.messager
  53. .alert(
  54. "system prompt",
  55. "Delete successful!");
  56. $("#dg").datagrid(
  57. "reload");
  58. } else {
  59. $.messager
  60. .alert(
  61. "system prompt",
  62. "Can't delete superAdmin or current admin!");
  63. }
  64. }, "json");
  65. }
  66. });
  67. }
  68. function openAdminAddDialog() {
  69. $("#dlg").dialog("open").dialog("setTitle", "Add new admin");
  70. url = "${pageContext.request.contextPath}/admin/save";
  71. }
  72. /* 保存管理员,根据不同的 url 选择是添加还是修改 */
  73. function saveAdmin() {
  74. $("#fm").form("submit", {
  75. url : url,
  76. onSubmit : function() {
  77. return $(this).form("validate");
  78. },
  79. success : function(result) {
  80. $.messager.alert("system prompt", "Save successful!");
  81. resetValue();
  82. $("#dlg").dialog("close");
  83. $("#dg").datagrid("reload");
  84. }
  85. });
  86. }
  87. function openAdminModifyDialog() {
  88. var selectedRows = $("#dg").datagrid('getSelections');
  89. if (selectedRows.length != 1) {
  90. $.messager.alert("system prompt", "Please choose a data to edit!");
  91. return;
  92. }
  93. var row = selectedRows[0];
  94. if (row.id == 1) {
  95. $.messager.alert("system prompt",
  96. "Can't modity superadmin' information!");
  97. return;
  98. }
  99. $("#dlg").dialog("open").dialog("setTitle", "Edit admin information");
  100. $('#fm').form('load', row);
  101. $("#password").val("******");
  102. url = "${pageContext.request.contextPath}/admin/save?id=" + row.id;
  103. }
  104. function resetValue() {
  105. $("#username").val("");
  106. $("#password").val("");
  107. }
  108. function closeAdminDialog() {
  109. $("#dlg").dialog("close");
  110. resetValue();
  111. }
  112. </script>
  113. </head>
  114. <body style="margin: 1px;">
  115. <table id="dg" title="Admin Manage" class="easyui-datagrid"
  116. fitColumns="true" pagination="true" rownumbers="true"
  117. url="${pageContext.request.contextPath}/admin/list" fit="true"
  118. toolbar="#tb">
  119. <thead>
  120. <tr>
  121. <th field="cb" checkbox="true" align="center"></th>
  122. <th field="id" width="50" align="center">id</th>
  123. <th field="username" width="80" align="center">username</th>
  124. <th field="role_name" width="80" align="center">role_name</th>
  125. </tr>
  126. </thead>
  127. </table>
  128. <div id="tb">
  129. <div>
  130. <a href="javascript:openAdminAddDialog()" class="easyui-linkbutton"
  131. iconCls="icon-add" plain="true">Add</a> <a
  132. href="javascript:openAdminModifyDialog()" class="easyui-linkbutton"
  133. iconCls="icon-edit" plain="true">Modify</a> <a
  134. href="javascript:deleteAdmin()" class="easyui-linkbutton"
  135. iconCls="icon-remove" plain="true">Delete</a>
  136. </div>
  137. <div>
  138. &nbsp;Username:&nbsp;<input type="text" id="s_username" size="20"
  139. onkeydown="if(event.keyCode==13) searchAdmin()" /> <a
  140. href="javascript:searchAdmin()" class="easyui-linkbutton"
  141. iconCls="icon-search" plain="true">Search</a>
  142. </div>
  143. </div>
  144. <div id="dlg" class="easyui-dialog"
  145. style="width: 620px; height: 250px; padding: 10px 20px" closed="true"
  146. buttons="#dlg-buttons">
  147. <form id="fm" method="post">
  148. <table cellspacing="8px">
  149. <tr>
  150. <td>Username:</td>
  151. <td><input type="text" id="username" name="username"
  152. class="easyui-validatebox" required="true" />&nbsp;<font
  153. color="red">*</font></td>
  154. </tr>
  155. <tr>
  156. <td>Password:</td>
  157. <td><input type="text" id="password" name="password"
  158. class="easyui-validatebox" required="true" />&nbsp;<font
  159. color="red">*</font></td>
  160. </tr>
  161. </table>
  162. </form>
  163. </div>
  164. <div id="dlg-buttons">
  165. <a href="javascript:saveAdmin()" class="easyui-linkbutton"
  166. iconCls="icon-ok">Save</a> <a href="javascript:closeAdminDialog()"
  167. class="easyui-linkbutton" iconCls="icon-cancel">Close</a>
  168. </div>
  169. </body>
  170. </html>

2.5.2 postManage.jsp

在项目 hrmssrc->main->webapp->views 下新建 JSP 页面 postManage.jsp 作为公告管理页面,并添加如下代码:

  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. <title>postManage</title>
  8. <link rel="stylesheet" type="text/css"
  9. href="${pageContext.request.contextPath}/jquery-easyui-1.3.3/themes/default/easyui.css">
  10. <link rel="stylesheet" type="text/css"
  11. href="${pageContext.request.contextPath}/jquery-easyui-1.3.3/themes/icon.css">
  12. <script type="text/javascript"
  13. src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.min.js"></script>
  14. <script type="text/javascript"
  15. src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
  16. <script type="text/javascript"
  17. src="${pageContext.request.contextPath}/ueditor/ueditor.config.js">
  18. </script>
  19. <script type="text/javascript"
  20. src="${pageContext.request.contextPath}/ueditor/ueditor.all.min.js">
  21. </script>
  22. <script type="text/javascript"
  23. src="${pageContext.request.contextPath}/js/common.js"></script>
  24. <script type="text/javascript">
  25. var url;
  26. function ResetEditor() {
  27. UE.getEditor('myEditor', {
  28. initialFrameHeight : 480,
  29. initialFrameWidth : 660,
  30. enableAutoSave : false,
  31. elementPathEnabled : false,
  32. wordCount : false,
  33. });
  34. }
  35. /* 根据条件查询公告 */
  36. function searchPost() {
  37. $("#dg").datagrid('load', {
  38. "title" : $("#postTitle").val(),
  39. });
  40. }
  41. /* 删除公告,可以是多个 */
  42. function deletePost() {
  43. var selectedRows = $("#dg").datagrid('getSelections');
  44. if (selectedRows.length == 0) {
  45. $.messager.alert("system prompt", "Please choose a data to edit!");
  46. return;
  47. }
  48. var strIds = [];
  49. for ( var i = 0; i < selectedRows.length; i++) {
  50. strIds.push(selectedRows[i].id);
  51. }
  52. var ids = strIds.join(",");
  53. $.messager
  54. .confirm(
  55. "Please choose a data to edit!",
  56. "Do you want to delete the <font color=red>"
  57. + selectedRows.length + "</font> data?",
  58. function(r) {
  59. if (r) {
  60. $
  61. .post(
  62. "${pageContext.request.contextPath}/post/delete",
  63. {
  64. ids : ids
  65. },
  66. function(result) {
  67. if (result.success) {
  68. $.messager
  69. .alert(
  70. "system prompt",
  71. "Delete successful!");
  72. $("#dg").datagrid(
  73. "reload");
  74. } else {
  75. $.messager
  76. .alert(
  77. "system prompt",
  78. "Delete error!");
  79. }
  80. }, "json");
  81. }
  82. });
  83. }
  84. function openPostAddDialog() {
  85. var html = '<div id="myEditor" name="content"></div>';
  86. $('#editor').append(html);
  87. ResetEditor(editor);
  88. var ue = UE.getEditor('myEditor');
  89. ue.ready(function() {
  90. ue.setContent("");
  91. });
  92. $("#dlg").dialog("open").dialog("setTitle", "Add post");
  93. url = "${pageContext.request.contextPath}/post/save";
  94. }
  95. /* 保存公告,根据不同的 url 选择是添加还是修改 */
  96. function savePost() {
  97. $("#fm").form("submit", {
  98. url : url,
  99. onSubmit : function() {
  100. return $(this).form("validate");
  101. },
  102. success : function(result) {
  103. $.messager.alert("system prompt", "Save successful!");
  104. $("#dlg").dialog("close");
  105. $("#dg").datagrid("reload");
  106. resetValue();
  107. }
  108. });
  109. }
  110. function openPostModifyDialog() {
  111. var selectedRows = $("#dg").datagrid('getSelections');
  112. if (selectedRows.length != 1) {
  113. $.messager.alert("system prompt", "Please choose a data to edit!");
  114. return;
  115. }
  116. var row = selectedRows[0];
  117. $("#dlg").dialog("open").dialog("setTitle", "Edit post");
  118. $('#fm').form('load', row);
  119. var html = '<div id="myEditor" name="content"></div>';
  120. $('#editor').append(html);
  121. ResetEditor(editor);
  122. var ue = UE.getEditor('myEditor');
  123. ue.ready(function() {
  124. ue.setContent(row.content);
  125. });
  126. url = "${pageContext.request.contextPath}/post/save?id=" + row.id;
  127. }
  128. function formatHref(val, row) {
  129. return "<a href='${pageContext.request.contextPath}/post/getById?id="
  130. + row.id + "' target='_blank'>Show Content</a>";
  131. }
  132. function resetValue() {
  133. $("#title").val("");
  134. $("#container").val("");
  135. ResetEditor();
  136. }
  137. function closePostDialog() {
  138. $("#dlg").dialog("close");
  139. resetValue();
  140. }
  141. </script>
  142. </head>
  143. <body style="margin: 1px;" id="ff">
  144. <table id="dg" title="Post Manage" class="easyui-datagrid"
  145. pagination="true" rownumbers="true" fit="true"
  146. data-options="pageSize:10"
  147. url="${pageContext.request.contextPath}/post/list" toolbar="#tb">
  148. <thead data-options="frozen:true">
  149. <tr>
  150. <th field="cb" checkbox="true" align="center"></th>
  151. <th field="id" width="10%" align="center" hidden="true">id</th>
  152. <th field="title" width="300" align="center">title</th>
  153. <th field="date" width="150" align="center">create_date</th>
  154. <th field="admin.username" width="150" align="center">announcer</th>
  155. <th field="content" width="150" align="center"
  156. formatter="formatHref">operation</th>
  157. </tr>
  158. </thead>
  159. </table>
  160. <div id="tb">
  161. <div>
  162. <a href="javascript:openPostAddDialog()" class="easyui-linkbutton"
  163. iconCls="icon-add" plain="true">Add</a> <a
  164. href="javascript:openPostModifyDialog()" class="easyui-linkbutton"
  165. iconCls="icon-edit" plain="true">Modify</a> <a
  166. href="javascript:deletePost()" class="easyui-linkbutton"
  167. iconCls="icon-remove" plain="true">Delete</a>
  168. </div>
  169. <div>
  170. &nbsp;Title:&nbsp;<input type="text" id="postTitle" size="20"
  171. onkeydown="if(event.keyCode==13) searchPost()" />&nbsp; <a
  172. href="javascript:searchPost()" class="easyui-linkbutton"
  173. iconCls="icon-search" plain="true">Search</a>
  174. </div>
  175. </div>
  176. <div id="dlg" class="easyui-dialog"
  177. style="width: 850px; height: 555px; padding: 10px 20px; position: relative; z-index: 1000;"
  178. closed="true" buttons="#dlg-buttons">
  179. <form id="fm" method="post">
  180. <table cellspacing="8px">
  181. <tr>
  182. <td>TiTle:</td>
  183. <td><input type="text" id="title" name="title"
  184. class="easyui-validatebox" required="true" />&nbsp;<font
  185. color="red">*</font></td>
  186. </tr>
  187. <tr>
  188. <td>Content:</td>
  189. <td id="editor"></td>
  190. </tr>
  191. </table>
  192. </form>
  193. </div>
  194. <div id="dlg-buttons">
  195. <a href="javascript:savePost()" class="easyui-linkbutton"
  196. iconCls="icon-ok">Save</a> <a href="javascript:closePostDialog()"
  197. class="easyui-linkbutton" iconCls="icon-cancel">Close</a>
  198. </div>
  199. </body>
  200. </html>

2.5.3 deptManage.jsp

在项目 hrmssrc->main->webapp->views 下新建 JSP 页面 deptManage.jsp 作为部门管理页面,并添加如下代码:

  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. <title>Insert title here</title>
  8. <link rel="stylesheet" type="text/css"
  9. href="${pageContext.request.contextPath}/jquery-easyui-1.3.3/themes/default/easyui.css">
  10. <link rel="stylesheet" type="text/css"
  11. href="${pageContext.request.contextPath}/jquery-easyui-1.3.3/themes/icon.css">
  12. <script type="text/javascript"
  13. src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.min.js"></script>
  14. <script type="text/javascript"
  15. src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
  16. <script type="text/javascript">
  17. var url;
  18. /* 根据条件查询部门 */
  19. function searchDept() {
  20. $("#dg").datagrid('load', {
  21. "name" : $("#s_name").val()
  22. });
  23. }
  24. /* 删除部门,可以是多个 */
  25. function deleteDept() {
  26. var selectedRows = $("#dg").datagrid('getSelections');
  27. if (selectedRows.length == 0) {
  28. $.messager.alert("system prompt",
  29. "Please choose the data to delete!");
  30. return;
  31. }
  32. var strIds = [];
  33. for ( var i = 0; i < selectedRows.length; i++) {
  34. strIds.push(selectedRows[i].id);
  35. }
  36. var ids = strIds.join(",");
  37. $.messager
  38. .confirm(
  39. "system prompt",
  40. "Do you want to delete the <font color=red>"
  41. + selectedRows.length + "</font> data?",
  42. function(r) {
  43. if (r) {
  44. $
  45. .post(
  46. "${pageContext.request.contextPath}/dept/delete",
  47. {
  48. ids : ids
  49. },
  50. function(result) {
  51. if (result.success) {
  52. $.messager
  53. .alert(
  54. "system prompt",
  55. "Delete successful!");
  56. $("#dg").datagrid(
  57. "reload");
  58. } else {
  59. $.messager
  60. .alert(
  61. "system prompt",
  62. "Delete error! The department has employees!");
  63. }
  64. }, "json");
  65. }
  66. });
  67. }
  68. function openDeptAddDialog() {
  69. $("#dlg").dialog("open").dialog("setTitle", "Add new department");
  70. url = "${pageContext.request.contextPath}/dept/save";
  71. }
  72. /* 保存部门,根据不同的 url 选择是添加还是修改 */
  73. function saveDept() {
  74. $("#fm").form("submit", {
  75. url : url,
  76. onSubmit : function() {
  77. return $(this).form("validate");
  78. },
  79. success : function(result) {
  80. $.messager.alert("system prompt", "Save successful!");
  81. resetValue();
  82. $("#dlg").dialog("close");
  83. $("#dg").datagrid("reload");
  84. }
  85. });
  86. }
  87. function openDeptModifyDialog() {
  88. var selectedRows = $("#dg").datagrid('getSelections');
  89. if (selectedRows.length != 1) {
  90. $.messager.alert("system prompt", "Please choose a data to edit!");
  91. return;
  92. }
  93. var row = selectedRows[0];
  94. $("#dlg").dialog("open").dialog("setTitle",
  95. "Edit department information");
  96. $('#fm').form('load', row);
  97. url = "${pageContext.request.contextPath}/dept/save?id=" + row.id;
  98. }
  99. function resetValue() {
  100. $("#name").val("");
  101. $("#description").val("");
  102. }
  103. function closeDeptDialog() {
  104. $("#dlg").dialog("close");
  105. resetValue();
  106. }
  107. </script>
  108. </head>
  109. <body style="margin: 1px;">
  110. <table id="dg" title="Department Manage" class="easyui-datagrid"
  111. fitColumns="true" pagination="true" rownumbers="true"
  112. url="${pageContext.request.contextPath}/dept/list" fit="true"
  113. toolbar="#tb">
  114. <thead>
  115. <tr>
  116. <th field="cb" checkbox="true" align="center"></th>
  117. <th field="id" width="50" align="center" hidden="true">id</th>
  118. <th field="name" width="80" align="center">name</th>
  119. <th field="description" width="200" align="center">description</th>
  120. </tr>
  121. </thead>
  122. </table>
  123. <div id="tb">
  124. <div>
  125. <a href="javascript:openDeptAddDialog()" class="easyui-linkbutton"
  126. iconCls="icon-add" plain="true">Add</a> <a
  127. href="javascript:openDeptModifyDialog()" class="easyui-linkbutton"
  128. iconCls="icon-edit" plain="true">Modify</a> <a
  129. href="javascript:deleteDept()" class="easyui-linkbutton"
  130. iconCls="icon-remove" plain="true">Delete</a>
  131. </div>
  132. <div>
  133. &nbsp;Name:&nbsp;<input type="text" id="s_name" size="20"
  134. onkeydown="if(event.keyCode==13) searchDept()" /> <a
  135. href="javascript:searchDept()" class="easyui-linkbutton"
  136. iconCls="icon-search" plain="true">Search</a>
  137. </div>
  138. </div>
  139. <div id="dlg" class="easyui-dialog"
  140. style="width: 450px; height: 250px; padding: 10px 20px" closed="true"
  141. buttons="#dlg-buttons">
  142. <form id="fm" method="post">
  143. <table cellspacing="8px">
  144. <tr>
  145. <td>Name:</td>
  146. <td><input type="text" id="name" name="name"
  147. style="width: 180px" class="easyui-validatebox" required="true" />&nbsp;<font
  148. color="red">*</font></td>
  149. </tr>
  150. <tr>
  151. <td>Description:</td>
  152. <td><textarea id="description" name="description"
  153. style="width: 180px; height: 80px;" class="easyui-validatebox"
  154. required="true"></textarea>&nbsp;<font color="red">*</font></td>
  155. </tr>
  156. </table>
  157. </form>
  158. </div>
  159. <div id="dlg-buttons">
  160. <a href="javascript:saveDept()" class="easyui-linkbutton"
  161. iconCls="icon-ok">Save</a> <a href="javascript:closeDeptDialog()"
  162. class="easyui-linkbutton" iconCls="icon-cancel">Close</a>
  163. </div>
  164. </body>
  165. </html>

2.5.4 positionManage.jsp

在项目 hrmssrc->main->webapp->views 下新建 JSP 页面 positionManage.jsp 作为职位管理页面,并添加如下代码:

  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. <title>Insert title here</title>
  8. <link rel="stylesheet" type="text/css"
  9. href="${pageContext.request.contextPath}/jquery-easyui-1.3.3/themes/default/easyui.css">
  10. <link rel="stylesheet" type="text/css"
  11. href="${pageContext.request.contextPath}/jquery-easyui-1.3.3/themes/icon.css">
  12. <script type="text/javascript"
  13. src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.min.js"></script>
  14. <script type="text/javascript"
  15. src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
  16. <script type="text/javascript">
  17. var url;
  18. /* 根据条件查询职位 */
  19. function searchPosition() {
  20. $("#dg").datagrid('load', {
  21. "name" : $("#s_name").val()
  22. });
  23. }
  24. /* 删除职位,可以是多个 */
  25. function deletePosition() {
  26. var selectedRows = $("#dg").datagrid('getSelections');
  27. if (selectedRows.length == 0) {
  28. $.messager.alert("system prompt",
  29. "Please choose the data to delete!");
  30. return;
  31. }
  32. var strIds = [];
  33. for ( var i = 0; i < selectedRows.length; i++) {
  34. strIds.push(selectedRows[i].id);
  35. }
  36. var ids = strIds.join(",");
  37. $.messager
  38. .confirm(
  39. "system prompt",
  40. "Do you want to delete the <font color=red>"
  41. + selectedRows.length + "</font> data?",
  42. function(r) {
  43. if (r) {
  44. $
  45. .post(
  46. "${pageContext.request.contextPath}/position/delete",
  47. {
  48. ids : ids
  49. },
  50. function(result) {
  51. if (result.success) {
  52. $.messager
  53. .alert(
  54. "system prompt",
  55. "Delete successful!");
  56. $("#dg").datagrid(
  57. "reload");
  58. } else {
  59. $.messager
  60. .alert(
  61. "system prompt",
  62. "Delete error! The position has employees!");
  63. }
  64. }, "json");
  65. }
  66. });
  67. }
  68. function openPositionAddDialog() {
  69. $("#dlg").dialog("open").dialog("setTitle", "Add new position");
  70. url = "${pageContext.request.contextPath}/position/save";
  71. }
  72. /* 保存职位,根据不同的 url 选择是添加还是修改 */
  73. function savePosition() {
  74. $("#fm").form("submit", {
  75. url : url,
  76. onSubmit : function() {
  77. return $(this).form("validate");
  78. },
  79. success : function(result) {
  80. $.messager.alert("system prompt", "Save successful!");
  81. resetValue();
  82. $("#dlg").dialog("close");
  83. $("#dg").datagrid("reload");
  84. }
  85. });
  86. }
  87. function openPositionModifyDialog() {
  88. var selectedRows = $("#dg").datagrid('getSelections');
  89. if (selectedRows.length != 1) {
  90. $.messager.alert("system prompt", "Please choose a data to edit!");
  91. return;
  92. }
  93. var row = selectedRows[0];
  94. $("#dlg").dialog("open")
  95. .dialog("setTitle", "Edit position information");
  96. $('#fm').form('load', row);
  97. url = "${pageContext.request.contextPath}/position/save?id=" + row.id;
  98. }
  99. function resetValue() {
  100. $("#name").val("");
  101. $("#description").val("");
  102. }
  103. function closePositionDialog() {
  104. $("#dlg").dialog("close");
  105. resetValue();
  106. }
  107. </script>
  108. </head>
  109. <body style="margin: 1px;">
  110. <table id="dg" title="Position Manage" class="easyui-datagrid"
  111. fitColumns="true" pagination="true" rownumbers="true"
  112. url="${pageContext.request.contextPath}/position/list" fit="true"
  113. toolbar="#tb">
  114. <thead>
  115. <tr>
  116. <th field="cb" checkbox="true" align="center"></th>
  117. <th field="id" width="50" align="center" hidden="true">id</th>
  118. <th field="name" width="80" align="center">name</th>
  119. <th field="description" width="200" align="center">description</th>
  120. </tr>
  121. </thead>
  122. </table>
  123. <div id="tb">
  124. <div>
  125. <a href="javascript:openPositionAddDialog()"
  126. class="easyui-linkbutton" iconCls="icon-add" plain="true">Add</a> <a
  127. href="javascript:openPositionModifyDialog()"
  128. class="easyui-linkbutton" iconCls="icon-edit" plain="true">Modify</a>
  129. <a href="javascript:deletePosition()" class="easyui-linkbutton"
  130. iconCls="icon-remove" plain="true">Delete</a>
  131. </div>
  132. <div>
  133. &nbsp;Name:&nbsp;<input type="text" id="s_name" size="20"
  134. onkeydown="if(event.keyCode==13) searchPosition()" /> <a
  135. href="javascript:searchPosition()" class="easyui-linkbutton"
  136. iconCls="icon-search" plain="true">Search</a>
  137. </div>
  138. </div>
  139. <div id="dlg" class="easyui-dialog"
  140. style="width: 450px; height: 250px; padding: 10px 20px" closed="true"
  141. buttons="#dlg-buttons">
  142. <form id="fm" method="post">
  143. <table cellspacing="8px">
  144. <tr>
  145. <td>Name:</td>
  146. <td><input type="text" id="name" name="name"
  147. style="width: 180px" class="easyui-validatebox" required="true" />&nbsp;<font
  148. color="red">*</font></td>
  149. </tr>
  150. <tr>
  151. <td>Description:</td>
  152. <td><textarea id="description" name="description"
  153. style="width: 180px; height: 80px;" class="easyui-validatebox"
  154. required="true"></textarea>&nbsp;<font color="red">*</font></td>
  155. </tr>
  156. </table>
  157. </form>
  158. </div>
  159. <div id="dlg-buttons">
  160. <a href="javascript:savePosition()" class="easyui-linkbutton"
  161. iconCls="icon-ok">Save</a> <a href="javascript:closePositionDialog()"
  162. class="easyui-linkbutton" iconCls="icon-cancel">Close</a>
  163. </div>
  164. </body>
  165. </html>

2.5.5 employeeManage.jsp

在项目 hrmssrc->main->webapp->views 下新建 JSP 页面 employeeManage.jsp 作为员工管理页面,并添加如下代码:

  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. <title>Insert title here</title>
  8. <link rel="stylesheet" type="text/css"
  9. href="${pageContext.request.contextPath}/jquery-easyui-1.3.3/themes/default/easyui.css">
  10. <link rel="stylesheet" type="text/css"
  11. href="${pageContext.request.contextPath}/jquery-easyui-1.3.3/themes/icon.css">
  12. <script type="text/javascript"
  13. src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.min.js"></script>
  14. <script type="text/javascript"
  15. src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
  16. <script type="text/javascript"
  17. src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
  18. <script type="text/javascript">
  19. var url;
  20. var firstDepartmentId;
  21. var firstDepartmentName;
  22. var firstPositionId;
  23. var firstPositionName;
  24. var submitDeptId;
  25. var submitPosId;
  26. var updateFlag;
  27. /* 根据条件查询员工 */
  28. function searchEmpl() {
  29. $("#dg").datagrid('load', {
  30. "id" : $("#e_id").val(),
  31. "name" : $("#e_name").val(),
  32. "department.name" : $("#e_dept").val(),
  33. "position.name" : $("#e_position").val(),
  34. "sex" : $("#e_sex").val()
  35. });
  36. }
  37. /* 删除员工,可以是多个 */
  38. function deleteEmpl() {
  39. var selectedRows = $("#dg").datagrid('getSelections');
  40. if (selectedRows.length == 0) {
  41. $.messager.alert("system prompt",
  42. "Please choose the data to delete!");
  43. return;
  44. }
  45. var strIds = [];
  46. for ( var i = 0; i < selectedRows.length; i++) {
  47. strIds.push(selectedRows[i].id);
  48. }
  49. var ids = strIds.join(",");
  50. $.messager
  51. .confirm(
  52. "system prompt",
  53. "Do you want to delete the <font color=red>"
  54. + selectedRows.length + "</font> data?",
  55. function(r) {
  56. if (r) {
  57. $
  58. .post(
  59. "${pageContext.request.contextPath}/empl/delete",
  60. {
  61. ids : ids
  62. },
  63. function(result) {
  64. if (result.success) {
  65. $.messager
  66. .alert(
  67. "system prompt",
  68. "Delete successful!");
  69. $("#dg").datagrid(
  70. "reload");
  71. } else {
  72. $.messager
  73. .alert(
  74. "system prompt",
  75. "Delete error!");
  76. }
  77. }, "json");
  78. }
  79. });
  80. }
  81. function openEmplAddDialog() {
  82. $("#dlg").dialog("open").dialog("setTitle", "Add new employee");
  83. $("#id").attr("readOnly", false);
  84. url = "${pageContext.request.contextPath}/empl/save";
  85. updateFlag = "no";
  86. }
  87. /* 保存员工,根据不同的 url 选择是添加还是修改 */
  88. function saveEmpl() {
  89. submitDeptId = $("#dept").combobox('getValue');
  90. submitPosId = $("#pos").combobox('getValue');
  91. $("#fm")
  92. .form(
  93. "submit",
  94. {
  95. url : url + "?dept_id= " + submitDeptId
  96. + "&pos_id= " + submitPosId
  97. + "&updateFlag=" + updateFlag,
  98. onSubmit : function() {
  99. var msg = "";
  100. // 进行输入信息的校验,非空,id 和 phone 的格式
  101. if (!$(this).form("validate")) {
  102. msg = "all information can't be empty!";
  103. } else if (!/^[0-9]+$/.test($("#id").val())) {
  104. msg = "Please input number type for id!";
  105. } else if (!/^1[3|5|7|8]\d{9}$/
  106. .test($("#phone").val())) {
  107. msg = "Please input right phone!";
  108. }
  109. if (msg != "") {
  110. $.messager.alert("system prompt", msg);
  111. return false;
  112. } else {
  113. return true;
  114. }
  115. },
  116. success : function(data) {
  117. var result = eval('(' + data + ')');
  118. if (result.success) {
  119. $.messager.alert("system prompt",
  120. "Save successful!");
  121. resetValue();
  122. $("#dlg").dialog("close");
  123. $("#dg").datagrid("reload");
  124. } else {
  125. $.messager
  126. .alert("system prompt",
  127. "The id already exists,please input a new id!");
  128. }
  129. }
  130. });
  131. }
  132. function openEmplModifyDialog() {
  133. var selectedRows = $("#dg").datagrid('getSelections');
  134. if (selectedRows.length != 1) {
  135. $.messager.alert("system prompt", "Please choose a data to edit!");
  136. return;
  137. }
  138. var row = selectedRows[0];
  139. $("#dlg").dialog("open")
  140. .dialog("setTitle", "Edit employee information");
  141. $("#id").attr("readOnly", true);
  142. $('#fm').form('load', row);
  143. $('#birthday').datebox('setValue', row.birthday);
  144. $('#dept').combobox('setValue', row.department.id);
  145. $('#dept').combobox('setText', row.department.name);
  146. $('#pos').combobox('setValue', row.position.id);
  147. $('#pos').combobox('setText', row.position.name);
  148. url = "${pageContext.request.contextPath}/empl/save";
  149. updateFlag = "yes";
  150. }
  151. function resetValue() {
  152. $("#id").val("");
  153. $("#id").attr("readOnly", false);
  154. $("#name").val("");
  155. $('#sex').combobox('setValue', "male");
  156. $("#phone").val("");
  157. $("#email").val("");
  158. $("#address").val("");
  159. $('#education').combobox('setValue', "Bachelor");
  160. $('#birthday').datebox('setValue', formatterDate(new Date()));
  161. $('#dept').combobox('setValue', firstDepartmentId);
  162. $('#dept').combobox('setText', firstDepartmentName);
  163. $('#pos').combobox('setValue', firstPositionId);
  164. $('#pos').combobox('setText', firstPositionName);
  165. }
  166. function closeEmplDialog() {
  167. $("#dlg").dialog("close");
  168. resetValue();
  169. }
  170. /* 为部门的 combobox 设默认值 */
  171. $(document).ready(function() {
  172. $.ajax({
  173. url : '${pageContext.request.contextPath}/dept/getcombobox',
  174. type : 'post',
  175. success : function(data) {
  176. if (data) {
  177. $('#dept').combobox('setValue', data[0].id);
  178. $('#dept').combobox('setText', data[0].name);
  179. firstDepartmentId = data[0].id;
  180. firstDepartmentName = data[0].name;
  181. }
  182. }
  183. });
  184. });
  185. /* 为职位的 combobox 设默认值 */
  186. $(document).ready(function() {
  187. $.ajax({
  188. url : '${pageContext.request.contextPath}/position/getcombobox',
  189. type : 'post',
  190. success : function(data) {
  191. if (data) {
  192. $('#pos').combobox('setValue', data[0].id);
  193. $('#pos').combobox('setText', data[0].name);
  194. firstPositionId = data[0].id;
  195. firstPositionName = data[0].name;
  196. }
  197. }
  198. });
  199. });
  200. /* 设置 datebox 默认值为指定格式的当前日期 */
  201. formatterDate = function(date) {
  202. var day = date.getDate() > 9 ? date.getDate() : "0" + date.getDate();
  203. var month = (date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : "0"
  204. + (date.getMonth() + 1);
  205. return date.getFullYear() + '-' + month + '-' + day;
  206. };
  207. window.onload = function() {
  208. $('#birthday').datebox('setValue', formatterDate(new Date()));
  209. };
  210. </script>
  211. </head>
  212. <body style="margin: 1px;">
  213. <table id="dg" title="Employee Manage" class="easyui-datagrid"
  214. fitColumns="true" pagination="true" rownumbers="true"
  215. url="${pageContext.request.contextPath}/empl/list" fit="true"
  216. toolbar="#tb">
  217. <thead>
  218. <tr>
  219. <th field="cb" checkbox="true" align="center"></th>
  220. <th field="id" width="50" align="center">id</th>
  221. <th field="name" width="80" align="center">name</th>
  222. <th field="sex" width="50" align="center">sex</th>
  223. <th field="phone" width="80" align="center">phone</th>
  224. <th field="email" width="100" align="center">email</th>
  225. <th field="address" width="80" align="center">address</th>
  226. <th field="education" width="60" align="center">education</th>
  227. <th field="birthday" width="80" align="center">birthday</th>
  228. <th field="department.id" width="50" align="center" hidden="true">dept_id</th>
  229. <th field="department.name" width="80" align="center">department</th>
  230. <th field="position.id" width="50" align="center" hidden="true">pos_id</th>
  231. <th field="position.name" width="80" align="center">position</th>
  232. </tr>
  233. </thead>
  234. </table>
  235. <div id="tb">
  236. <div>
  237. <a href="javascript:openEmplAddDialog()" class="easyui-linkbutton"
  238. iconCls="icon-add" plain="true">Add</a> <a
  239. href="javascript:openEmplModifyDialog()" class="easyui-linkbutton"
  240. iconCls="icon-edit" plain="true">Modify</a> <a
  241. href="javascript:deleteEmpl()" class="easyui-linkbutton"
  242. iconCls="icon-remove" plain="true">Delete</a>
  243. </div>
  244. <div>
  245. <table>
  246. <tr>
  247. <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ID:&nbsp;
  248. <input type="text" id="e_id" size="20"
  249. onkeydown="if(event.keyCode==13) searchEmpl()" />
  250. </td>
  251. <td>&nbsp;Name:&nbsp; <input type="text" id="e_name" size="20"
  252. onkeydown="if(event.keyCode==13) searchEmpl()" />
  253. </td>
  254. <td>&nbsp;Department:&nbsp; <input type="text" id="e_dept"
  255. size="20" onkeydown="if(event.keyCode==13) searchEmpl()" />
  256. </td>
  257. </tr>
  258. <tr>
  259. <td>&nbsp;Position:&nbsp;<input type="text" id="e_position"
  260. size="20" onkeydown="if(event.keyCode==13) searchEmpl()" />
  261. </td>
  262. <td>&nbsp;&nbsp;&nbsp;&nbsp;Sex:&nbsp; <input type="text"
  263. id="e_sex" size="20"
  264. onkeydown="if(event.keyCode==13) searchEmpl()" />
  265. </td>
  266. <td>&nbsp;&nbsp;&nbsp;<a href="javascript:searchEmpl()"
  267. class="easyui-linkbutton" iconCls="icon-search" plain="true">Search</a>
  268. </td>
  269. </tr>
  270. </table>
  271. </div>
  272. </div>
  273. <div id="dlg" class="easyui-dialog"
  274. style="width: 500px; height: 550px; padding: 10px 20px" closed="true"
  275. buttons="#dlg-buttons">
  276. <form id="fm" method="post">
  277. <table cellspacing="8px">
  278. <tr>
  279. <td>ID:</td>
  280. <td><input type="text" id="id" name="id" style="width: 210px"
  281. class="easyui-validatebox"
  282. data-options="required:true,validType:'digits'" />&nbsp;<font
  283. color="red">*</font></td>
  284. </tr>
  285. <tr>
  286. <td>Name:</td>
  287. <td><input type="text" id="name" name="name"
  288. style="width: 210px" class="easyui-validatebox" required="true" />&nbsp;<font
  289. color="red">*</font></td>
  290. </tr>
  291. <tr>
  292. <td>Sex:</td>
  293. <td><select id="sex" class="easyui-combobox" name="sex"
  294. style="width: 220px; heigth: 60px"
  295. data-options="editable:false,panelHeight:'auto'">
  296. <option>male</option>
  297. <option>female</option>
  298. </select></td>
  299. </tr>
  300. <tr>
  301. <td>Phone:</td>
  302. <td><input type="text" id="phone" name="phone"
  303. style="width: 210px" class="easyui-validatebox" required="true" />&nbsp;<font
  304. color="red">*</font></td>
  305. </tr>
  306. <tr>
  307. <td>Email:</td>
  308. <td><input type="text" id="email" name="email"
  309. style="width: 210px" class="easyui-validatebox"
  310. data-options="required:true,validType:'email'" />&nbsp;<font
  311. color="red">*</font></td>
  312. </tr>
  313. <tr>
  314. <td>Address:</td>
  315. <td><textarea id="address" name="address"
  316. style="width: 210px; height: 50px" class="easyui-validatebox"
  317. required="true"></textarea>&nbsp;<font color="red">*</font></td>
  318. </tr>
  319. <tr>
  320. <td>Education:</td>
  321. <td><select id="education" class="easyui-combobox"
  322. name="education" style="width: 220px; heigth: 60px"
  323. data-options="editable:false,panelHeight:'auto'">
  324. <option>Bachelor</option>
  325. <option>Master</option>
  326. <option>Doctor</option>
  327. </select></td>
  328. </tr>
  329. <tr>
  330. <td>Birthday:</td>
  331. <td><input id="birthday" name="birthday" type="text"
  332. class="easyui-datebox" data-options="editable:false"
  333. required="required" style="width: 220px"></td>
  334. </tr>
  335. <tr>
  336. <td>Department:</td>
  337. <td><select class="easyui-combobox" id="dept" name="dept"
  338. data-options="url:'${pageContext.request.contextPath}/dept/getcombobox',
  339. method:'post',
  340. valueField:'id',
  341. textField:'name',
  342. editable:false,
  343. panelHeight:'auto'"
  344. style="width: 220px"></select></td>
  345. </tr>
  346. <tr>
  347. <td>Position:</td>
  348. <td><select class="easyui-combobox" id="pos" name="pos"
  349. data-options="url:'${pageContext.request.contextPath}/position/getcombobox',
  350. method:'post',
  351. valueField:'id',
  352. textField:'name',
  353. editable:false,
  354. panelHeight:'auto'"
  355. style="width: 220px"></select></td>
  356. </tr>
  357. </table>
  358. </form>
  359. </div>
  360. <div id="dlg-buttons">
  361. <a href="javascript:saveEmpl()" class="easyui-linkbutton"
  362. iconCls="icon-ok">Save</a> <a href="javascript:closeEmplDialog()"
  363. class="easyui-linkbutton" iconCls="icon-cancel">Close</a>
  364. </div>
  365. </body>
  366. </html>

三、实验总结

到这里我们就完成了表现层 JSP 代码的实现,下一节我们将完成拦截器和 Spring MVC 框架的整合。

表现层 JSP 页面实现的更多相关文章

  1. 表现层(jsp)、持久层(类似dao)、业务层(逻辑层、service层)、模型(javabean)、控制层(action)

    转自:http://www.blogjava.net/jiabao/archive/2007/04/08/109189.html 为了实现web层(struts)和持久层(Hibernate)之间的松 ...

  2. java 表现层:jsp、freemarker、velocity

    在java领域,表现层技术主要有三种:jsp.freemarker.velocity. jsp是大家最熟悉的技术 优点: 1.功能强大,可以写java代码 2.支持jsp标签(jsp tag) 3.支 ...

  3. CGI servlet Applet Scriptlet Scriptlet JSP data layer(数据层),business layer(业务层), presentation layer(表现层)

    https://en.wikipedia.org/wiki/Common_Gateway_Interface In computing, Common Gateway Interface (CGI) ...

  4. SpringMVC的controller层接收来自jsp页面通过<a href="/user/userUpdateInfo/>的中文乱码问题

    这种情况是,jsp页面的中文正常显示,数据的中文也是正常显示,但是在Controller层接收到的中文是乱码,如下图所示: 解决方法:在Controller层对前台传递的中文乱码进行处理,将它转换成u ...

  5. 系统管理模块_部门管理_改进_抽取添加与修改JSP页面中的公共代码_在显示层抽取BaseAction_合并Service层与Dao层

    系统管理模块_部门管理_改进1:抽取添加与修改JSP页面中的公共代码 commons.jspf <%@ page language="java" import="j ...

  6. 表现层(jsp)、持久层(dao)、业务层(逻辑层、service)

    转自:http://www.blogjava.net/jiabao/archive/2007/04/08/109189.html 为了实现web层(struts)和持久层(Hibernate)之间的松 ...

  7. Spring MVC控制层传递对象后在JSP页面中的取值方法

    List<Order> orders = new ArrayList<Order>(); for (int i = 0; i < 3; i++) { Order t = ...

  8. 关于ajax的controller层返回jsp页面多个list

    @RequestMapping(value ="findFansChangeRate") @ResponseBody public AjaxJson findFansChangeR ...

  9. 将图片至于jsp页面上(层)

    <div style="position: relative"> <span style="position: relative; top: 1px; ...

随机推荐

  1. Python之code对象与pyc文件(三)

    上一节:Python之code对象与pyc文件(二) 向pyc写入字符串 在了解Python如何将字符串写入到pyc文件的机制之前,我们先来了解一下结构体WFILE: marshal.c typede ...

  2. Makefile基础(一)

    在大型的C语言项目中,一般都是由多个源文件编译链接形成的可执行程序,而这些源文件的处理步骤,通常交给Makefile来管理,Makefile定义了一系列的规则来指定,哪些文件需要先编译,哪些文件需要后 ...

  3. Selenium WebDriver-操作键盘事件

    # 注意: !!!操作操作系统的按键,需要先装pywin32,然后通过交互模式import win32api和import win32con判断是否安装成功,需要重启下cmd进入交互模式# 下载链接: ...

  4. SDOJ 3696 Tree

    描述 给你一个无向带权连通图,每条边是黑色或白色.让你求一棵最小权的恰好有need条白色边的生成树. 题目保证有解. 输入 第一行V,E,need分别表示点数,边数和需要的白色边数. 接下来E行 每行 ...

  5. python随机数的产生

    导入 random模块  >>> import random 1.  random.random random.random()用于生成一个0到1的随机浮点数: 0 <= n ...

  6. NumPy数值计算(1)

    NumPy数值计算(1) 将列表转为NumPy中的array from __future__ import print_function from numpy import * import oper ...

  7. PHP变量的生命周期

    变量不仅有其特定的作用范围,还有其存活的周期--生命周期.变量的生命周期指的是变量可被使用的一个时间段,在这个时间段内变量是有效的,一旦超出这个时间段变量就会失效,我们就不能够再访问到该变量的值了. ...

  8. 集合篇 —— Collection(1):JDK 中的重复实现问题

    1.      问题的提出 在 Java 的集合体系当中,无论是 List(列表)还是 Set(集),在设计的时候都存在一个很奇怪的现象:这两种集合的接口,Java 都为其设计了抽象类 Abstrac ...

  9. 二进制<4>

    位运算简介及实用技巧(四):实战篇 下面分享的是我自己写的三个代码,里面有些题目也是我自己出的.这些代码都是在我的Pascal时代写的,恕不提供C语言了.代码写得并不好,我只是想告诉大家位运算在实战中 ...

  10. java面试题之你了解守护线程吗?它和非守护线程有什么区别

    程序运行完毕,jvm会等待非守护线程完成后关闭,但是jvm不会等待守护线程. 守护线程最典型的的例子是:GC线程