JSP實(shí)現(xiàn)簡單人事管理系統(tǒng)
本文實(shí)例為大家分享了JSP實(shí)現(xiàn)簡單人事管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
此系統(tǒng)使用jsp實(shí)現(xiàn),其中包含了jsp九大內(nèi)置對象和四大作用域的相關(guān)知識,采用map集合模擬數(shù)據(jù)庫的方式,實(shí)現(xiàn)用戶登錄、員工信息展示、員工信息修改功能。
JSP的九大內(nèi)置對象:Application,Config,Exception,Out,PageContent,Page,Request,Respsonse,Sesstion
JSP的四大作用域:Application Sesstion Page request
項(xiàng)目結(jié)構(gòu)
Emp.java 員工信息
package org.wang.model;
public class Emp {
private String account;
private String name;
private String password;
private String email;
public Emp(String account, String name, String password, String email) {
this.account = account;
this.name = name;
this.password = password;
this.email = email;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
DBUtil.java 用集合模擬數(shù)據(jù)庫存放員工信息
package org.wang.db;
import org.wang.model.Emp;
import java.util.HashMap;
import java.util.Map;
//用集合模擬操縱數(shù)據(jù)庫
public class DBUtil{
public static Map<String, Emp> map = new HashMap<String, Emp>();
//用靜態(tài)代碼塊完成對map中的值的初始化操作
static {
map.put("001",new Emp("001","zhangsan","111111","111111@qq.com"));
map.put("002",new Emp("002","lisi","121212","121212@qq.com"));
map.put("003",new Emp("003","wangwu","131313","131313@qq.com"));
map.put("004",new Emp("004","zhaoliu","141414","141414@qq.com"));
}
//判斷用戶名和密碼是否正確
public static boolean selectEmpByAccountAndPassword(Emp emp){
//用戶輸入的信息存入到emp對象中,判斷emp對象中的值是否和map中的值對應(yīng)
boolean flag = false;
//遍歷當(dāng)前map集合中的key
for (String key : map.keySet()){
Emp e = map.get(key);
//判斷用戶傳入的值是否與map集合中的值相等
if(emp.getAccount().equals(e.getAccount()) && emp.getPassword().equals(e.getPassword())){
flag = true;
break;
}
}
return flag;
}
}
index.jsp 登錄界面
<%-- Created by IntelliJ IDEA. User: wangy Date: 2018/11/8 Time: 8:19 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>人事管理系統(tǒng)登錄</title> </head> <body> <h3 align="center">人事管理系統(tǒng)登錄頁面</h3> <hr> <%--action代表了服務(wù)器端的處理程序--%> <form action="index-control.jsp"> <table align="center"> <tr> <td> 賬號: </td> <td> <input type="text" name="account"> </td> </tr> <tr> <td> 密碼: </td> <td> <input type="password" name="password"> </td> </tr> <tr> <td> <input type="submit" value="登錄"> </td> </tr> </table> </form> </body> </html>
index-control.jsp 登錄界面的控制界面,用于處理用戶登錄信息是否與map集合中的員工信息匹配
<%--
Created by IntelliJ IDEA.
User: wangy
Date: 2018/11/8
Time: 9:09
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" errorPage="error.jsp" %>
<%@ page import="org.wang.db.*,org.wang.model.*" %>
<%@ page import="java.util.Map" %>
<html>
<head>
<title>人事管理系統(tǒng)</title>
</head>
<body>
<%--獲取用戶輸入的賬號及密碼,并調(diào)用DBUtil中的方法判斷信息是否存在
request:獲取請求信息
request.getParameter(String name):可以通過一個控件的name屬性來獲取控件的值
out.println(); 向頁面輸出信息
--%>
<%
// 獲取用戶輸入的賬號及密碼
String account = request.getParameter("account");
String password = request.getParameter("password");
//將用戶輸入的賬號和密碼封裝到一個Emp對象中
Emp emp = new Emp(account,null,password,null);
boolean flag = DBUtil.selectEmpByAccountAndPassword(emp);
//獲取map集合
Map<String,Emp> map = DBUtil.map;
if(flag==true){
//設(shè)置session
session.setAttribute("account",account);
//使用application來獲取系統(tǒng)訪問量
Object o = application.getAttribute("count");
//判斷如果當(dāng)前用戶為第一個登錄,則application中的值為空,此時(shí)將訪問量設(shè)置為1
if(o == null){
application.setAttribute("count",1);
}else{
//count原來為String,強(qiáng)轉(zhuǎn)為int型,并做+1操作
int count = Integer.parseInt(o.toString());
application.setAttribute("count",count+1);
}
%>
<%--獲取訪問量并顯示到頁面上--%>
<h3 align="right">當(dāng)前訪問量:<%=application.getAttribute("count")%></h3>
<%--獲取session中的值并顯示到頁面上--%>
<h3 align="center">歡迎來到人事管理系統(tǒng)</h3>
<h3 align="right">登錄賬戶:<%=session.getAttribute("account")%></h3>
<hr>
<table align="center" border="1" width="500px">
<tr>
<td>
賬號
</td>
<td>
員工姓名
</td>
<td>
郵箱
</td>
<td>
修改
</td>
</tr>
<%--用for循環(huán)自動根據(jù)模擬數(shù)據(jù)庫中的數(shù)據(jù)生成單元行,顯示出員工信息表--%>
<%
for (String key : map.keySet()){
Emp e = map.get(key);
%>
<tr>
<td>
<%=e.getAccount()%>
</td>
<td>
<%=e.getName()%>
</td>
<td>
<%=e.getEmail()%>
</td>
<td>
<%--點(diǎn)擊修改跳轉(zhuǎn)到update.jsp頁面,采用URL方式傳遞參數(shù),地址欄會顯示數(shù)據(jù)信息--%>
<%--相鄰兩個jsp頁面?zhèn)鬟f數(shù)據(jù)時(shí),可通過URL參數(shù)的方式傳遞--%>
<%--語法規(guī)則:頁面?key1=value1 & key2=value2--%>
<a href="update.jsp?account=<%=e.getAccount()%>&name=<%=e.getName()%>&email=<%=e.getEmail()%>" rel="external nofollow" >修改</a>
</td>
</tr>
<%
}
%>
</table>
<%
}else{
throw new Exception("登錄失敗");
}
%>
</body>
</html>
error.jsp
<%-- Created by IntelliJ IDEA. User: wangy Date: 2018/11/8 Time: 16:01 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" isErrorPage="true" %> <html> <head> <title>Title</title> </head> <body> <%=exception.getMessage()%> </body> </html>
update.jsp 修改員工信息頁面
%--
Created by IntelliJ IDEA.
User: wangy
Date: 2018/11/8
Time: 15:27
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>員工更新頁面</title>
</head>
<body>
<h3 align="right">當(dāng)前訪問量:<%=application.getAttribute("count")%></h3>
<h3 align="center">員工更新頁面</h3>
<%--獲取session中的值并顯示到頁面上--%>
<h3 align="right">登錄賬戶:<%=session.getAttribute("account")%></h3>
<hr>
<form action="update-control.jsp">
<table align="center" border="1" width="500px">
<tr>
<%--value="<%=request.getParameter("account")%>"可用于實(shí)現(xiàn)數(shù)據(jù)的回顯--%>
<td>賬號</td>
<td><input type="text" name="account" value="<%=request.getParameter("account")%>"></td>
</tr>
<tr>
<td>姓名</td>
<td><input type="text" name="name" value="<%=request.getParameter("name")%>"></td>
</tr>
<tr>
<td>郵箱</td>
<td><input type="text" name="email" value="<%=request.getParameter("email")%>"></td>
</tr>
<tr>
<td>
<input type="submit" value="修改">
</td>
</tr>
</table>
</form>
</body>
</html>
update-control 執(zhí)行修改操作的控制頁面
<%--
Created by IntelliJ IDEA.
User: wangy
Date: 2018/11/9
Time: 9:46
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@page import="org.wang.db.*,org.wang.model.*" %>
<%@ page import="java.util.Map" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%
//獲取map集合
Map<String,Emp> map = DBUtil.map;
//修改信息
//獲取當(dāng)前需要修改的員工的account
Emp emp = map.get(request.getParameter("account"));
//把獲取到的當(dāng)前員工的信息重新set
emp.setName(request.getParameter("name"));
emp.setEmail(request.getParameter("email"));
%>
<h3 align="center">修改員工信息成功</h3>
</body>
</html>
運(yùn)行效果
登錄界面
登錄成功后進(jìn)入員工信息顯示頁面
修改員工信息(這里用了數(shù)據(jù)回顯)
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。
上一篇:JSP頁面的靜態(tài)包含和動態(tài)包含使用方法
欄 目:JSP編程
下一篇:jsp實(shí)現(xiàn)textarea中的文字保存換行空格存到數(shù)據(jù)庫的方法
本文標(biāo)題:JSP實(shí)現(xiàn)簡單人事管理系統(tǒng)
本文地址:http://www.jygsgssxh.com/a1/JSPbiancheng/11428.html
您可能感興趣的文章
- 01-11在JSP中使用formatNumber控制要顯示的小數(shù)位數(shù)方法
- 01-11jsp文件下載功能實(shí)現(xiàn)代碼
- 01-11JSP頁面跳轉(zhuǎn)方法大全
- 01-11Spring獲取ApplicationContext對象工具類的實(shí)現(xiàn)方法
- 01-11jsp 使用request為頁面添加靜態(tài)數(shù)據(jù)的實(shí)例
- 01-11web前端超出兩行用省略號表示的實(shí)現(xiàn)方法
- 01-11JSP servlet實(shí)現(xiàn)文件上傳下載和刪除
- 01-11JSP狀態(tài)管理的簡單介紹
- 01-11jsp+servlet實(shí)現(xiàn)文件上傳與下載功能
- 01-11將properties文件的配置設(shè)置為整個Web應(yīng)用的全局變量實(shí)現(xiàn)方法


閱讀排行
本欄相關(guān)
- 01-11web下載文件和跳轉(zhuǎn)的方法
- 01-11Spring注入Date類型的三種方法總結(jié)
- 01-11在JSP中使用formatNumber控制要顯示的小
- 01-11Properties 持久的屬性集的實(shí)例詳解
- 01-11EJB3.0部署消息驅(qū)動Bean拋javax.naming.Na
- 01-11jsp文件下載功能實(shí)現(xiàn)代碼
- 01-11JSP頁面跳轉(zhuǎn)方法大全
- 01-11詳解Spring的核心機(jī)制依賴注入
- 01-11jsp 使用request為頁面添加靜態(tài)數(shù)據(jù)的實(shí)
- 01-11Spring獲取ApplicationContext對象工具類的


