JSP implements the customer information management system and the Customer Information Management System
This example shares the code for implementing the Customer Information Management System in JSP for your reference. The details are as follows:
This is probably the case for the project. I drew it myself.
Logon interface code
Index. jsp: Completely technical, directly calling a servlet-controlled logon or not
<% @ Page language = "java" import = "java. util. *" pageEncoding = "UTF-8" %> <! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">
LoginServlet
Public class LoginServlet extends HttpServlet {public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {doPost (request, response);} public void doPost (HttpServletRequest request, response) throws ServletException, IOException {String name = request. getParameter ("name"); String pwd = request. getParameter ("pwd"); // you must Encapsulate the account password as a JavaBean to access the background database to verify logon. Here, if (name! = Null & name. startsWith ("hncu") & pwd! = Null & pwd. length ()> 3) {// login successful, visit the home page request. getSession (). setAttribute ("name", name); request. getRequestDispatcher ("/jsps/table. jsp "). forward (request, response);} else {// Logon Failed, repair and return to the logon interface response. sendRedirect (request. getContextPath () + "/index. jsp ");}}}
After entering, go to our homepage and click Add. A window will pop up at the beginning to let us enter the added information.
This technical principle
function add(){ var url = path+"/jsps/input.jsp"; var returnValue =window.showModalDialog(url, "","dialogHeight:400px;dialogWidth:300pxl;status:no"); if(returnValue){// alert(returnValue.id); realAdd(returnValue); }}
Url: the path of the pop-up window. The parameters in the pop-up window are set later.
The returned value can be dragged through this statement to provide
window.returnValue=obj;
The following is the process of adding
Homepage code and JS Code
<% @ Page language = "java" import = "java. util. *" pageEncoding = "UTF-8" %> <% @ taglib uri =" http://java.sun.com/jsp/jstl/core "Prefix =" c "%> <! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">
Table. js
Function add () {var url = path + "/jsps/input. jsp "; // var vReturnValue = window. showModalDialog (url, "", "dialogWidth: 400px; dialogHeight: 200px; status: no;"); var returnValue = window. showModalDialog (url, "", "dialogHeight: 400px; dialogWidth: 300pxl; status: no"); if (returnValue) {// alert (returnValue. id); realAdd (returnValue) ;}// Insert the encapsulated data to the table function realAdd (obj) {var tb = document. getElementById ("tb "); Var oTr = tb. insertRow (); var oCell = oTr. insertCell (); oCell. innerHTML = '<input type = "checkbox" name = "chk" onclick = "subchk (this);"/>'; oCell = oTr. insertCell (); oCell. innerHTML = obj. name; oCell = oTr. insertCell (); oCell. innerHTML = obj. age; oCell = oTr. insertCell (); oCell. innerHTML = obj. addr; oCell = oTr. insertCell (); oCell. innerHTML = obj. id; oCell. className = "iid";} // check box, click the Select All box above. All the check boxes below must select function chk (obj) {var chks = document. getElementsByName ("chk"); var len = chks. length; for (var I = 0; I <len; I ++) {chks [I]. checked = obj. checked; }}// by counting the selection of the following check boxes, determine the three statuses of the above review box function subchk (obj) {var chks = document. getElementsByName ("chk"); var n = 0; // count the number of rows selected in the table row for (var I = 0; I <chks. length; I ++) {if (chks [I]. checked) {n ++;} var parentChk = document. getElementById ("parentChk"); if (N = 0) {parentChk. indeterminate = false; // ※※※parentchk cannot be saved. checked = false;} else if (n = chks. length) {parentChk. indeterminate = false; // ※※※parentchk cannot be saved. checked = true;} else {parentChk. indeterminate = true ;}// submit the id of the row selected by the user to the background. After the background is deleted successfully, the return result is truefunction del () {// in the future, we should use json to encapsulate all IDs and submit them to the background for processing (we haven't learned it yet ). // Currently, we use character concatenation. var tb = document with potential bugs. getElementById ("tb"); var chks = document. getElementsByName ("chk"); var ids = ""; for (var I = 0; I <chks. length; I ++) {if (chks [I]. checked) {// alert ("aaa"); // obtain the id value of the row var oTr = chks [I]. parentNode. parentNode; // alert (oTr); var id = oTr. cells [4]. innerText; // alert (id); if (ids = "") {ids = id;} else {ids = ids + "," + id ;}}} if (ids = "") {alert ("select the row to delete");} else {Document. getElementById ("ids"). value = ids; document. forms ['f1']. submit () ;}} function realDel (boo) {if (! Boo) {alert ("deletion failed! "); Return;} var tb = document. getElementById ("tb"); var chks = document. getElementsByName ("chk"); var len = chks. length; // reverse delete for (var I = len-1; I> = 0; I --) {if (chks [I]. checked) {tb. deleteRow (I + 1) ;}} var chks = document. getElementsByName ("chk"); var n = 0; // count the number of rows selected in the table row for (var I = 0; I <chks. length; I ++) {if (chks [I]. checked) {n ++ ;}/// after deletion, refine the status of the preceding check box var parentChk = document. getElementById ("parentChk"); if (n = 0) {parentChk. indeterminate = false; // ※※※parentchk cannot be saved. checked = false;} else if (n = chks. length) {parentChk. indeterminate = false; // ※※※parentchk cannot be saved. checked = true;} else {parentChk. indeterminate = true ;}}
Input. jsp
<% @ Page language = "java" import = "java. util. *" pageEncoding = "UTF-8" %> <% @ taglib uri =" http://java.sun.com/jsp/jstl/core "Prefix =" c "%> <! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">
Save. jsp
<%@ page language="java" import="java.util.*;" pageEncoding="UTF-8"%><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %><script type="text/javascript"> var user = new Object(); user.name = '<c:out value="${user.name}"/>'; user.id = '<c:out value="${user.id}"/>'; user.age = '<c:out value="${user.age}"/>'; user.addr = '<c:out value="${user.addr}"/>'; parent.realSave(user);</script>
The following is the deletion process.
Delback. jsp
<% @ Page language = "java" import = "java. util. * "pageEncoding =" UTF-8 "%> <% @ taglib uri =" http://java.sun.com/jsp/jstl/core "prefix =" c "%> <script type =" text/javascript "> // use jstl in var boo = "<c: out value = '$ {succ}'/> "; parent. realDel (boo); </script>
For more information, see management system development.
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.