项目编号:BS-XX-013
本项目基于JSP/Servlet技术实现开发,开发工具采用IDEA或ECLIPSE,数据库采用MYSQL数据库。
首次使用,需要进入src/com/util/DBOK 修改数据库的相关信息,系统设置mysql的用户名为root,密码为root,可以根据需要修改为自己的账户信息。
实验室设备管理系统主要包含两个用户角色,一个是超级管理员,可以进行系统的各种管理工作,一个是普通管理员,主要进入系统进行相应的信息查看工作。系统的主要功能包含有:登陆用户的信息修改,系统用户管理,使用设备的用户信息管理,实验设备管理,设备借出管理,设备维修管理,共建记录管理,实验室设备统计(图形报表的形式展示),注销退出,登陆系统。
下面就部分功能进行功能展示:
用户登陆:
登陆后主界面:
系统用户管理:
用户信息管理:
设备信息管理:
设备借出管理:
设备维修管理:
共建记录管理:
实验室设备统计:
以上是展示的系统部分功能,此项目功能完整,运行无误,比较适合毕业设计使用。
核心代码:
package com.action;
/**
* 管理员登陆 增加 修改 删除
*/
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import java.util.StringTokenizer;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.bean.ComBean;
import com.util.Constant;
import com.util.MD5;
public class AdminServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public AdminServlet() {
super();
}
/**
* Destruction of the servlet.
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet.
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
/**
* The doPost method of the servlet.
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType(Constant.CONTENTTYPE);
request.setCharacterEncoding(Constant.CHARACTERENCODING);
String date=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime());
String date2=new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
try{
String method=request.getParameter("method").trim();
ComBean cBean = new ComBean();
HttpSession session = request.getSession();
if(method.equals("one")){//用户登录
String username = request.getParameter("username");
String password = request.getParameter("password");
String sf = request.getParameter("sf");
String sql="select realname from admin where username='"+username+"' and password='"+password+"' and sf='"+sf+"' ";
String str=cBean.getString(sql);
if(str==null){
request.setAttribute("message", "登录信息错误!");
request.getRequestDispatcher("index.jsp").forward(request, response);
}
else{
session.setAttribute("user", username); session.setAttribute("sf", sf);
request.getRequestDispatcher("admin/index.jsp").forward(request, response);
}
}
else if(method.equals("uppwd")){//修改密码
String username=(String)session.getAttribute("user");
String oldpwd = request.getParameter("oldpwd");
String newpwd = request.getParameter("newpwd");
String str=cBean.getString("select id from admin where username='"+username+"' and password='"+oldpwd+"'");
if(str==null){
request.setAttribute("message", "原始密码信息错误!");
request.getRequestDispatcher("admin/system/editpwd.jsp").forward(request, response);
}
else{
int flag=cBean.comUp("update admin set password='"+newpwd+"' where username='"+username+"'");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/system/editpwd.jsp").forward(request, response);
}
else {
request.setAttribute("message", "操作失败!");
request.getRequestDispatcher("admin/system/editpwd.jsp").forward(request, response);
}
}
}
else if(method.equals("adminexit")){//退出登录
session.removeAttribute("user"); session.removeAttribute("sf");
request.getRequestDispatcher("index.jsp").forward(request, response);
}
else if(method.equals("addm")){//增加系统用户
String username = request.getParameter("username");
String password = request.getParameter("password");
String realname = request.getParameter("realname");
String sex = request.getParameter("sex");
String age = request.getParameter("age");
String address = request.getParameter("address");
String tel = request.getParameter("tel");
String str=cBean.getString("select id from admin where username='"+username+"'");
if(str==null){
int flag=cBean.comUp("insert into admin(username,password,realname,sex,age,address,tel,addtime ) " +
"values('"+username+"','"+password+"','"+realname+"','"+sex+"','"+age+"','"+address+"','"+tel+"','"+date+"' )");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/system/index.jsp").forward(request, response);
}
else {
request.setAttribute("message", "操作失败!");
request.getRequestDispatcher("admin/system/index.jsp").forward(request, response);
}
}
else{
request.setAttribute("message", "该用户名已存在!");
request.getRequestDispatcher("admin/system/index.jsp").forward(request, response);
}
}
else if(method.equals("upm")){//修改系统用户
String id = request.getParameter("id");
String password = request.getParameter("password");
String realname = request.getParameter("realname");
String sex = request.getParameter("sex");
String age = request.getParameter("age");
String address = request.getParameter("address");
String tel = request.getParameter("tel");
int flag=cBean.comUp("update admin set password='"+password+"',realname='"+realname+"',sex='"+sex+"',age='"+age+"'," +
"address='"+address+"',tel='"+tel+"' where id='"+id+"'");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/system/index.jsp").forward(request, response);
}
else {
request.setAttribute("message", "操作失败!");
request.getRequestDispatcher("admin/system/index.jsp").forward(request, response);
}
}
else if(method.equals("delm")){//删除系统用户
String id = request.getParameter("id");
int flag=cBean.comUp("delete from admin where id='"+id+"'");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/system/index.jsp").forward(request, response);
}
else {
request.setAttribute("message", "操作失败!");
request.getRequestDispatcher("admin/system/index.jsp").forward(request, response);
}
}
else{//无参数传入转到错误页面
request.getRequestDispatcher("error.jsp").forward(request, response);
}
}catch(Exception e){
e.printStackTrace();
request.getRequestDispatcher("error.jsp").forward(request, response);
}
}
/**
* Initialization of the servlet.
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
// Put your code here
}
}
package com.action;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.bean.ComBean;
import com.util.Constant;
public class ComServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public ComServlet() {
super();
}
/**
* Destruction of the servlet.
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet.
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
/**
* The doPost method of the servlet.
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType(Constant.CONTENTTYPE);
request.setCharacterEncoding(Constant.CHARACTERENCODING);
HttpSession session = request.getSession();
ComBean cBean = new ComBean();
String date=new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
String date2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime());
String method = request.getParameter("method");
if(method.equals("addview1")){
//String xm="";String xb="";String nl="";String st="";String hj="";String sfz="";String lxr="";
//String dh="";String zz="";String cw="";String hg="";String rz="";String cy="";
String name = request.getParameter("name");
String sex = request.getParameter("sex");
String age = request.getParameter("age");
String build = request.getParameter("build");
int flag = cBean.comUp("insert into view1(name,sex,age,build) values('"+name+"','"+sex+"','"+age+"','"+build+"')");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/view1/index.jsp").forward(request, response);
}
else{
request.setAttribute("message", "操作失败!");
request.getRequestDispatcher("admin/view1/index.jsp").forward(request, response);
}
}
else if(method.equals("upview1")){ 修改信息
String id=request.getParameter("id");
String name = request.getParameter("name");
String sex= request.getParameter("sex");
String age = request.getParameter("age");
String build= request.getParameter("build");
int flag = cBean.comUp("update view1 set name='"+name+"',sex='"+sex+"',age='"+age+"',build='"+build+"' where id='"+id+"'");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/view1/index.jsp").forward(request, response);
}
else{
request.setAttribute("message", "操作失败!");
request.getRequestDispatcher("admin/view1/index.jsp").forward(request, response);
}
}
else if(method.equals("delview1")){//删除信息
String id = request.getParameter("id");
int flag = cBean.comUp("delete from view1 where id='"+id+"'");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/view1/index.jsp").forward(request, response);
}
else{
request.setAttribute("message", "系统维护中,请稍后再试!");
request.getRequestDispatcher("admin/view1/index.jsp").forward(request, response);
}
}
else if(method.equals("addview2")){
String lend1 = request.getParameter("lend1");
String lend2= request.getParameter("lend2");
String lend3 = request.getParameter("lend3");
String lend4 = request.getParameter("lend4");
String lend5= request.getParameter("lend5");
String lend6 = request.getParameter("lend6");
String lend7 = request.getParameter("lend7");
String lend8 = request.getParameter("lend8");
int flag = cBean.comUp("insert into view2(lend1,lend2,lend3,lend4,lend5,lend6,lend7,lend8) values('"+lend1+"','"+lend2+"','"+lend3+"','"+lend4+"','"+lend5+"','"+lend6+"','"+lend7+"','"+lend8+"')");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/view2/index.jsp").forward(request, response);
}
else{
request.setAttribute("message", "操作失败!");
request.getRequestDispatcher("admin/view2/index.jsp").forward(request, response);
}
}
else if(method.equals("upview2")){
String id=request.getParameter("id");
String lend1= request.getParameter("lend1");
String lend2 = request.getParameter("lend2");
String lend3 = request.getParameter("lend3");
String lend4= request.getParameter("lend4");
String lend5 = request.getParameter("lend5");
String lend6 = request.getParameter("lend6");
String lend7 = request.getParameter("lend7");
String lend8 = request.getParameter("lend8");
int flag = cBean.comUp("update view2 set lend1='"+lend1+"',lend2='"+lend2+"',lend3='"+lend3+"',lend4='"+lend4+"',lend5='"+lend5+"',lend6='"+lend6+"',lend7='"+lend7+"',lend8='"+lend8+"' where id='"+id+"'");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/view2/index.jsp").forward(request, response);
}
else{
request.setAttribute("message", "操作失败!");
request.getRequestDispatcher("admin/view2/index.jsp").forward(request, response);
}
}
else if(method.equals("delview2")){
String id = request.getParameter("id");
int flag = cBean.comUp("delete from view2 where id='"+id+"'");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/view2/index.jsp").forward(request, response);
}
else{
request.setAttribute("message", "系统维护中,请稍后再试!");
request.getRequestDispatcher("admin/view2/index.jsp").forward(request, response);
}
}
else if(method.equals("addview3")){
String information = request.getParameter("information");
String total = request.getParameter("total");
String phone = request.getParameter("phone");
int flag = cBean.comUp("insert into view3(information,total,phone) values('"+information+"','"+total+"','"+phone+"' )");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/view3/index.jsp").forward(request, response);
}
else{
request.setAttribute("message", "操作失败!");
request.getRequestDispatcher("admin/view3/index.jsp").forward(request, response);
}
}
else if(method.equals("upview3")){
String id=request.getParameter("id");
String information = request.getParameter("information");
String total = request.getParameter("total");
String phone = request.getParameter("phone");
int flag = cBean.comUp("update view3 set information='"+information+"',total='"+total+"',phone='"+phone+"' where id='"+id+"'");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/view3/index.jsp").forward(request, response);
}
else{
request.setAttribute("message", "操作失败!");
request.getRequestDispatcher("admin/view3/index.jsp").forward(request, response);
}
}
else if(method.equals("delview3")){
String id = request.getParameter("id");
int flag = cBean.comUp("delete from view3 where id='"+id+"'");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/view3/index.jsp").forward(request, response);
}
else{
request.setAttribute("message", "系统维护中,请稍后再试!");
request.getRequestDispatcher("admin/view3/index.jsp").forward(request, response);
}
}
else if(method.equals("addview4")){
String number = request.getParameter("number");
String name= request.getParameter("name");
String area = request.getParameter("area");
String price = request.getParameter("price");
String status = request.getParameter("status");
int flag = cBean.comUp("insert into view4(number,name,area,price,status) values('"+number+"','"+name+"','"+area+"','"+price+"','"+status+"')");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/view4/index.jsp").forward(request, response);
}
else{
request.setAttribute("message", "操作失败!");
request.getRequestDispatcher("admin/view4/index.jsp").forward(request, response);
}
}
else if(method.equals("upview4")){
String id=request.getParameter("id");
String number = request.getParameter("number");
String name = request.getParameter("name");
String area = request.getParameter("area");
String price= request.getParameter("price");
String status = request.getParameter("status");
int flag = cBean.comUp("update view4 set number='"+number+"',name='"+name+"',area='"+area+"',price='"+price+"',status='"+status+"' where id='"+id+"'");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/view4/index.jsp").forward(request, response);
}
else{
request.setAttribute("message", "操作失败!");
request.getRequestDispatcher("admin/view4/index.jsp").forward(request, response);
}
}
else if(method.equals("delview4")){
String id = request.getParameter("id");
int flag = cBean.comUp("delete from view4 where id='"+id+"'");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/view4/index.jsp").forward(request, response);
}
else{
request.setAttribute("message", "操作失败!");
request.getRequestDispatcher("admin/view4/index.jsp").forward(request, response);
}
}
else if(method.equals("addview5")){
String Repairnumber = request.getParameter("Repairnumber");
String BuildName = request.getParameter("BuildName");
String Repairdate = request.getParameter("Repairdate");
String Repairtime = request.getParameter("Repairtime");
String Repaircharge = request.getParameter("Repaircharge");
int flag = cBean.comUp("insert into view5(Repairnumber,BuildName,Repairdate,Repairtime,Repaircharge) values('"+Repairnumber+"','"+BuildName+"','"+Repairdate+"','"+Repairtime+"','"+Repaircharge+"')");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/view5/index.jsp").forward(request, response);
}
else{
request.setAttribute("message", "系统维护中,请稍后再试!");
request.getRequestDispatcher("admin/view5/index.jsp").forward(request, response);
}
}
else if(method.equals("upview5")){
String id=request.getParameter("id");
String Repairnumber = request.getParameter("Repairnumber");
String BuildName = request.getParameter("BuildName");
String Repairdate = request.getParameter("Repairdate");
String Repairtime= request.getParameter("Repairtime");
String Repaircharge = request.getParameter("Repaircharge");
int flag = cBean.comUp("update view5 set Repairnumber='"+Repairnumber+"',BuildName='"+BuildName+"',Repairdate='"+Repairdate+"',Repairtime='"+Repairtime+"',Repaircharge='"+Repaircharge+"' where id='"+id+"'");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/view5/index.jsp").forward(request, response);
}
else{
request.setAttribute("message", "操作失败!");
request.getRequestDispatcher("admin/view5/index.jsp").forward(request, response);
}
}
else if(method.equals("delview5")){
String id = request.getParameter("id");
int flag = cBean.comUp("delete from view5 where id='"+id+"'");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/view5/index.jsp").forward(request, response);
}
else{
request.setAttribute("message", "操作失败!");
request.getRequestDispatcher("admin/view5/index.jsp").forward(request, response);
}
}
else if(method.equals("addxz")){
String lr = request.getParameter("lr");
String fy = request.getParameter("fy");
String kc = request.getParameter("kc");
String zt = request.getParameter("zt");
String xx = request.getParameter("xx");
float sji=Float.parseFloat(fy)-Float.parseFloat(kc);
int flag = cBean.comUp("insert into xz(lr,fy,kc,zt,xx,sji) values('"+lr+"','"+fy+"','"+kc+"','"+zt+"','"+xx+"','"+sji+"' )");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/xz/index.jsp").forward(request, response);
}
else{
request.setAttribute("message", "系统维护中,请稍后再试!");
request.getRequestDispatcher("admin/xz/index.jsp").forward(request, response);
}
}
else if(method.equals("upxz")){
String id=request.getParameter("id");
String lr = request.getParameter("lr");
String fy = request.getParameter("fy");
String kc = request.getParameter("kc");
String zt = request.getParameter("zt");
String xx = request.getParameter("xx");
float sji=Float.parseFloat(fy)-Float.parseFloat(kc);
int flag = cBean.comUp("update xz set lr='"+lr+"',fy='"+fy+"',kc='"+kc+"',zt='"+zt+"',xx='"+xx+"',sji='"+sji+"' where id='"+id+"'");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/xz/index.jsp").forward(request, response);
}
else{
request.setAttribute("message", "操作失败!");
request.getRequestDispatcher("admin/xz/index.jsp").forward(request, response);
}
}
else if(method.equals("delxz")){
String id = request.getParameter("id");
int flag = cBean.comUp("delete from xz where id='"+id+"'");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/xz/index.jsp").forward(request, response);
}
else{
request.setAttribute("message", "操作失败!");
request.getRequestDispatcher("admin/xz/index.jsp").forward(request, response);
}
}
else if(method.equals("addhgqj")){
String lr = request.getParameter("lr");
String sj = request.getParameter("sj");
String xx = request.getParameter("xx");
int flag = cBean.comUp("insert into hgqj(lr,sj,xx) values('"+lr+"','"+sj+"','"+xx+"' )");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/hgqj/index.jsp").forward(request, response);
}
else{
request.setAttribute("message", "操作失败!");
request.getRequestDispatcher("admin/hgqj/index.jsp").forward(request, response);
}
}
else if(method.equals("uphgqj")){
String id=request.getParameter("id");
String lr = request.getParameter("lr");
String sj = request.getParameter("sj");
String xx = request.getParameter("xx");
int flag = cBean.comUp("update hgqj set lr='"+lr+"',sj='"+sj+"',xx='"+xx+"' where id='"+id+"'");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/hgqj/index.jsp").forward(request, response);
}
else{
request.setAttribute("message", "操作失败!");
request.getRequestDispatcher("admin/hgqj/index.jsp").forward(request, response);
}
}
else if(method.equals("delhgqj")){
String id = request.getParameter("id");
int flag = cBean.comUp("delete from hgqj where id='"+id+"'");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/hgqj/index.jsp").forward(request, response);
}
else{
request.setAttribute("message", "操作失败!");
request.getRequestDispatcher("admin/hgqj/index.jsp").forward(request, response);
}
}
}
/**
* Initialization of the servlet.
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
// Put your code here
}
}