基于javaweb+mysql的jsp+servlet机房管理系统机房维护与课程安排(java+servlet+mysql+jsp)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的JSP+Servlet机房管理系统机房维护与课程安排(java+servlet+mysql+jsp)
管理员:
admin 123456
老师:
老张 123456
老李 123456
public class shebei_servlet extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException
{
String type=req.getParameter("type");
if(type.endsWith("getshebeiList")){
getshebeiList(req, res);
}
if(type.endsWith("devchangeMana")){
devchangeMana(req, res);
}
if(type.endsWith("devchangeAdd")){
devchangeAdd(req, res);
}
if(type.endsWith("shebeiAdd")){
shebeiAdd(req, res);
}
if(type.endsWith("jiguiUpdate")){
jiguiUpdate(req, res);
}
if(type.endsWith("shebeiMana")){
shebeiMana(req, res);
}
if(type.endsWith("shiyongzheMana")){
shiyongzheMana(req, res);
}
if(type.endsWith("shiyongzheAdd")){
shiyongzheAdd(req, res);
req.getRequestDispatcher("admin/shebei/shebeiAdd.jsp").forward(req, res);
}
public void getJifangList(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
List jifangList = new ArrayList();
String sql = "select * from t_jifang where del='no'";
Object[] params = {};
DB mydb = new DB();
try {
mydb.doPstm(sql, params);
ResultSet rs = mydb.getRs();
while (rs.next()) {
Tjifang jifang = new Tjifang();
jifang.setId(rs.getInt("id"));
jifang.setFangjianhao(rs.getString("fangjianhao"));
jifang.setRenshu(rs.getInt("renshu"));
jifang.setJieshao(rs.getString("jieshao"));
jifang.setDel(rs.getString("del"));
jifangList.add(jifang);
}
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
mydb.closed();
req.setAttribute("jifangList", jifangList);
req.getRequestDispatcher("admin/jigui/jiguiAdd.jsp").forward(req, res);
}
public void jifangMana(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
List jifangList = new ArrayList();
String sql = "select * from t_jifang where del='no'";
Object[] params = {};
DB mydb = new DB();
try {
mydb.doPstm(sql, params);
ResultSet rs = mydb.getRs();
while (rs.next()) {
Tjifang jifang = new Tjifang();
jifang.setId(rs.getInt("id"));
jifang.setFangjianhao(rs.getString("fangjianhao"));
jifang.setRenshu(rs.getInt("renshu"));
jifang.setJieshao(rs.getString("jieshao"));
jifang.setDel(rs.getString("del"));
jifangList.add(jifang);
public class shebei_servlet extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException
{
String type=req.getParameter("type");
if(type.endsWith("getshebeiList")){
getshebeiList(req, res);
}
if(type.endsWith("devchangeMana")){
devchangeMana(req, res);
}
if(type.endsWith("devchangeAdd")){
devchangeAdd(req, res);
}
if(type.endsWith("shebeiAdd")){
shebeiAdd(req, res);
}
if(type.endsWith("jiguiUpdate")){
jiguiUpdate(req, res);
}
if(type.endsWith("shebeiMana")){
shebeiMana(req, res);
}
if(type.endsWith("shiyongzheMana")){
shiyongzheMana(req, res);
}
if(type.endsWith("shiyongzheAdd")){
shiyongzheAdd(req, res);
}
if(type.endsWith("jiguiEdit")){
jiguiEdit(req, res);
}
if(type.endsWith("shebeiDel")){
shebeiDel(req, res);
String userName=req.getParameter("userName");
String userPw=req.getParameter("userPw");
String sql="insert into t_admin(userId,userName,userPw) values(0,?,?)";
Object[] params={userName,userPw};
DB mydb=new DB();
mydb.doPstm(sql, params);
mydb.closed();
req.setAttribute("message", "操作成功");
req.setAttribute("path", "admin?type=adminMana");
String targetURL = "/common/success.jsp";
dispatch(targetURL, req, res);
}
public void adminDel(HttpServletRequest req,HttpServletResponse res)
{
System.out.println(req.getParameter("userId")+"**");
String sql="delete from t_admin where userId="+Integer.parseInt(req.getParameter("userId"));
Object[] params={};
DB mydb=new DB();
mydb.doPstm(sql, params);
mydb.closed();
req.setAttribute("message", "操作成功");
req.setAttribute("path", "admin?type=adminMana");
String targetURL = "/common/success.jsp";
dispatch(targetURL, req, res);
}
public void dispatch(String targetURI,HttpServletRequest request,HttpServletResponse response)
{
RequestDispatcher dispatch = getServletContext().getRequestDispatcher(targetURI);
try
{
dispatch.forward(request, response);
return;
}
catch (ServletException e)
{
TAdmin admin = (TAdmin) session.getAttribute("admin");
String sql = "update t_admin set userPw=? where userId=?";
Object[] params = {userPwNew, admin.getUserId()};
DB mydb = new DB();
mydb.doPstm(sql, params);
return "yes";
}
}
public class kebiao_servlet extends HttpServlet {
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
String type = req.getParameter("type");
if (type.endsWith("kebiaoAdd")) {
kebiaoAdd(req, res);
}
if (type.endsWith("kebiaoMana")) {
kebiaoMana(req, res);
}
if (type.endsWith("kebiaoDel")) {
kebiaoDel(req, res);
public class jifang_servlet extends HttpServlet {
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
String type = req.getParameter("type");
if (type.endsWith("getJifangList2")) {
getJifangList2(req, res);
}
if (type.endsWith("getJifangList")) {
getJifangList(req, res);
}
if (type.endsWith("jifangAdd")) {
jifangAdd(req, res);
}
if (type.endsWith("jifangMana")) {
jifangMana(req, res);
}
if (type.endsWith("jifangDel")) {
jifangDel(req, res);
}
if (type.endsWith("jifangAll")) {
jifangAll(req, res);
}
}
public void jifangAdd(HttpServletRequest req, HttpServletResponse res) {
}
public class admin_servlet extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException
{
String type=req.getParameter("type");
if(type.endsWith("adminMana"))
{
adminMana(req, res);
}
if(type.endsWith("adminAdd"))
{
adminAdd(req, res);
}
if(type.endsWith("adminDel"))
{
adminDel(req, res);
}
}
public void adminMana(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
{
List adminList=new ArrayList();
String sql="select * from t_admin";
Object[] params={};
DB mydb=new DB();
try
{
jifangAll(req, res);
}
}
public void jifangAdd(HttpServletRequest req, HttpServletResponse res) {
String fangjianhao = req.getParameter("fangjianhao");
int renshu = Integer.parseInt(req.getParameter("renshu"));
String jieshao = req.getParameter("jieshao").trim();
String del = "no";
String sql = "insert into t_jifang(fangjianhao,renshu,jieshao,del) values(?,?,?,?)";
Object[] params = {fangjianhao, renshu, jieshao, del};
DB mydb = new DB();
mydb.doPstm(sql, params);
mydb.closed();
req.setAttribute("message", "操作成功!!");
req.setAttribute("path", "jifang?type=jifangMana");
String targetURL = "/common/success.jsp";
dispatch(targetURL, req, res);
}
public void getJifangList2(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
List<Tjifang> jifangList = new ArrayList<Tjifang>();
String sql = "select * from t_jifang where del='no'";
Object[] params = {};
DB mydb = new DB();
try {
mydb.doPstm(sql, params);
ResultSet rs = mydb.getRs();
while (rs.next()) {
Tjifang jifang = new Tjifang();
jifang.setId(rs.getInt("id"));
jifang.setFangjianhao(rs.getString("fangjianhao"));
jifang.setRenshu(rs.getInt("renshu"));
jifang.setJieshao(rs.getString("jieshao"));
jifang.setDel(rs.getString("del"));
jifangList.add(jifang);
}
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
List<Tuser> userList = new ArrayList<Tuser>();
String sql2 = "select * from t_user where del='no'";
Object[] params2 = {};
laoshi.setLoginname(rs.getString("loginname"));
laoshi.setLoginpw(rs.getString("loginpw"));
laoshi.setDel(rs.getString("del"));
WebContext ctx = WebContextFactory.get();
HttpSession session = ctx.getSession();
session.setAttribute("userType", 1);
session.setAttribute("laoshi", laoshi);
}
rs.close();
} catch (SQLException e) {
System.out.println("登录失败!");
e.printStackTrace();
} finally {
mydb.closed();
}
}
if (userType == 2) {
}
WebContext ctx = WebContextFactory.get();
HttpSession session = ctx.getSession();
init(session);
return result;
}
private void init(HttpSession session) {
try {
List jifangList = new ArrayList();
String sql = "select * from t_jifang where del='no'";
Object[] params = {};
DB mydb = new DB();
try {
mydb.doPstm(sql, params);
ResultSet rs = mydb.getRs();
while (rs.next()) {
Tjifang jifang = new Tjifang();
jifang.setId(rs.getInt("id"));
jifang.setFangjianhao(rs.getString("fangjianhao"));
jifang.setRenshu(rs.getInt("renshu"));
jifang.setJieshao(rs.getString("jieshao"));
jifang.setDel(rs.getString("del"));
jifangList.add(jifang);
}
public void destroy()
{
}
}
public class admin_servlet extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException
{
String type=req.getParameter("type");
if(type.endsWith("adminMana"))
{
adminMana(req, res);
}
if(type.endsWith("adminAdd"))
{
adminAdd(req, res);
}
if(type.endsWith("adminDel"))
{
adminDel(req, res);
}
}
try {
List kechengList = new ArrayList();
String sql = "select * from t_kecheng where del='no'";
Object[] params = {};
DB mydb = new DB();
try {
mydb.doPstm(sql, params);
ResultSet rs = mydb.getRs();
while (rs.next()) {
Tkecheng kecheng = new Tkecheng();
kecheng.setId(rs.getInt("id"));
kecheng.setBianhao(rs.getString("bianhao"));
kecheng.setMingcheng(rs.getString("mingcheng"));
kecheng.setKeshi(rs.getString("keshi"));
kecheng.setDel(rs.getString("del"));
kechengList.add(kecheng);
}
session.setAttribute("kechengList",kechengList);
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
mydb.closed();
} catch (Exception e) {
e.printStackTrace();
}
try {
List laoshiList = new ArrayList();
String sql = "select * from t_laoshi where del='no'";
Object[] params = {};
DB mydb = new DB();
try {
mydb.doPstm(sql, params);
ResultSet rs = mydb.getRs();
while (rs.next()) {
Tlaoshi laoshi = new Tlaoshi();
laoshi.setId(rs.getInt("id"));
laoshi.setBianhao(rs.getString("bianhao"));
laoshi.setXingming(rs.getString("xingming"));
laoshi.setXingbie(rs.getString("xingbie"));
laoshi.setNianling(rs.getString("nianling"));
laoshi.setZhicheng(rs.getString("zhicheng"));
laoshi.setXibie(rs.getString("xibie"));
try {
List kechengList = new ArrayList();
String sql = "select * from t_kecheng where del='no'";
Object[] params = {};
DB mydb = new DB();
try {
mydb.doPstm(sql, params);
ResultSet rs = mydb.getRs();
while (rs.next()) {
Tkecheng kecheng = new Tkecheng();
kecheng.setId(rs.getInt("id"));
kecheng.setBianhao(rs.getString("bianhao"));
kecheng.setMingcheng(rs.getString("mingcheng"));
kecheng.setKeshi(rs.getString("keshi"));
kecheng.setDel(rs.getString("del"));
kechengList.add(kecheng);
}
session.setAttribute("kechengList",kechengList);
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
mydb.closed();
} catch (Exception e) {
e.printStackTrace();
}
try {
List laoshiList = new ArrayList();
String sql = "select * from t_laoshi where del='no'";
Object[] params = {};
DB mydb = new DB();
try {
mydb.doPstm(sql, params);
ResultSet rs = mydb.getRs();
while (rs.next()) {
Tlaoshi laoshi = new Tlaoshi();
laoshi.setId(rs.getInt("id"));
laoshi.setBianhao(rs.getString("bianhao"));
String targetURL = "/common/success.jsp";
dispatch(targetURL, req, res);
}
public void kebiaoMana_tea(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
List kebiaoList = new ArrayList();
String sql = "select * from t_kebiao where del='no' and laoshi_id=?";
Object[] params = {((Tlaoshi) (req.getSession().getAttribute("laoshi"))).getId()};
DB mydb = new DB();
try {
mydb.doPstm(sql, params);
ResultSet rs = mydb.getRs();
while (rs.next()) {
Tkebiao kebiao = new Tkebiao();
kebiao.setId(rs.getInt("id"));
kebiao.setShijian(rs.getString("shijian"));
kebiao.setJifang_id(rs.getInt("jifang_id"));
kebiao.setKecheng_id(rs.getInt("kecheng_id"));
kebiao.setLaoshi_id(rs.getInt("laoshi_id"));
kebiao.setBeizhu(rs.getString("beizhu"));
kebiao.setJifang(utilService.get_jifang(rs.getInt("jifang_id")));
kebiao.setKecheng(utilService.get_kecheng(rs.getInt("kecheng_id")));
kebiao.setLaoshi(utilService.get_laoshi(rs.getInt("laoshi_id")));
kebiaoList.add(kebiao);
}
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
mydb.closed();
req.setAttribute("kebiaoList", kebiaoList);
req.getRequestDispatcher("atea/kebiao/kebiaoMana_tea.jsp").forward(req, res);
}
public void dispatch(String targetURI, HttpServletRequest request, HttpServletResponse response) {
RequestDispatcher dispatch = getServletContext().getRequestDispatcher(targetURI);
try {
Tkecheng kecheng = new Tkecheng();
kecheng.setId(rs.getInt("id"));
kecheng.setBianhao(rs.getString("bianhao"));
kecheng.setMingcheng(rs.getString("mingcheng"));
kecheng.setKeshi(rs.getString("keshi"));
kecheng.setDel(rs.getString("del"));
kechengList.add(kecheng);
}
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
mydb.closed();
req.setAttribute("kechengList", kechengList);
req.getRequestDispatcher("admin/kecheng/kechengAll.jsp").forward(req, res);
}
public void dispatch(String targetURI, HttpServletRequest request, HttpServletResponse response) {
RequestDispatcher dispatch = getServletContext().getRequestDispatcher(targetURI);
try {
dispatch.forward(request, response);
return;
} catch (ServletException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
public void destroy() {
}
}
String xingbie = req.getParameter("xingbie");
String nianling = req.getParameter("nianling");
String zhicheng = req.getParameter("zhicheng");
String xibie = req.getParameter("xibie");
String sql = "update t_laoshi set bianhao=?,xingming=?,xingbie=?,nianling=?,zhicheng=?,xibie=? where id=?";
Object[] params = {bianhao, xingming, xingbie, nianling, zhicheng, xibie, id};
DB mydb = new DB();
mydb.doPstm(sql, params);
mydb.closed();
req.setAttribute("message", "操作成功");
req.setAttribute("path", "laoshi?type=laoshiMana");
String targetURL = "/common/success.jsp";
dispatch(targetURL, req, res);
}
public void laoshiAll(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
List laoshiList = new ArrayList();
String sql = "select * from t_laoshi where del='no'";
Object[] params = {};
DB mydb = new DB();
try {
mydb.doPstm(sql, params);
ResultSet rs = mydb.getRs();
while (rs.next()) {
Tlaoshi laoshi = new Tlaoshi();
laoshi.setId(rs.getInt("id"));
laoshi.setBianhao(rs.getString("bianhao"));
laoshi.setXingming(rs.getString("xingming"));
laoshi.setXingbie(rs.getString("xingbie"));
laoshi.setNianling(rs.getString("nianling"));
laoshi.setZhicheng(rs.getString("zhicheng"));
laoshi.setXibie(rs.getString("xibie"));
laoshi.setLoginname(rs.getString("loginname"));
laoshi.setLoginpw(rs.getString("loginpw"));
laoshi.setDel(rs.getString("del"));
laoshiList.add(laoshi);
}
rs.close();
} catch (Exception e) {
try {
mydb.doPstm(sql, params);
ResultSet rs = mydb.getRs();
while (rs.next()) {
Tjifang jifang = new Tjifang();
jifang.setId(rs.getInt("id"));
jifang.setFangjianhao(rs.getString("fangjianhao"));
jifang.setRenshu(rs.getInt("renshu"));
jifang.setJieshao(rs.getString("jieshao"));
jifang.setDel(rs.getString("del"));
jifangList.add(jifang);
}
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
mydb.closed();
req.setAttribute("jifangList", jifangList);
req.getRequestDispatcher("admin/jifang/jifangMana.jsp").forward(req, res);
}
public void jifangAll(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
List jifangList = new ArrayList();
String sql = "select * from t_jifang where del='no'";
Object[] params = {};
DB mydb = new DB();
try {
mydb.doPstm(sql, params);
ResultSet rs = mydb.getRs();
while (rs.next()) {
Tjifang jifang = new Tjifang();
jifang.setId(rs.getInt("id"));
jifang.setFangjianhao(rs.getString("fangjianhao"));
jifang.setRenshu(rs.getInt("renshu"));
jifang.setJieshao(rs.getString("jieshao"));
jifang.setDel(rs.getString("del"));
jifangList.add(jifang);
}
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
mydb.closed();
req.setAttribute("jifangList", jifangList);
req.getRequestDispatcher("admin/jifang/jifangAll.jsp").forward(req, res);
mydb.doPstm(sql, params);
mydb.closed();
req.setAttribute("message", "操作成功");
req.setAttribute("path", "kecheng?type=kechengMana");
String targetURL = "/common/success.jsp";
dispatch(targetURL, req, res);
}
public void kechengEditPre(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
Tkecheng kecheng = new Tkecheng();
String sql = "select * from t_kecheng where del='no' and id=?";
Object[] params = {Integer.parseInt(req.getParameter("id"))};
DB mydb = new DB();
try {
mydb.doPstm(sql, params);
ResultSet rs = mydb.getRs();
while (rs.next()) {
kecheng.setId(rs.getInt("id"));
kecheng.setBianhao(rs.getString("bianhao"));
kecheng.setMingcheng(rs.getString("mingcheng"));
kecheng.setKeshi(rs.getString("keshi"));
kecheng.setDel(rs.getString("del"));
}
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
mydb.closed();
req.setAttribute("kecheng", kecheng);
req.getRequestDispatcher("admin/kecheng/kechengEditPre.jsp").forward(req, res);
}
public void kechengEdit(HttpServletRequest req, HttpServletResponse res) {
int id = Integer.parseInt(req.getParameter("id"));
String bianhao = req.getParameter("bianhao");
String mingcheng = req.getParameter("mingcheng");
String keshi = req.getParameter("keshi");
kebiao.setId(rs.getInt("id"));
kebiao.setShijian(rs.getString("shijian"));
kebiao.setJifang_id(rs.getInt("jifang_id"));
kebiao.setKecheng_id(rs.getInt("kecheng_id"));
kebiao.setLaoshi_id(rs.getInt("laoshi_id"));
kebiao.setBeizhu(rs.getString("beizhu"));
kebiao.setJifang(utilService.get_jifang(rs.getInt("jifang_id")));
kebiao.setKecheng(utilService.get_kecheng(rs.getInt("kecheng_id")));
kebiao.setLaoshi(utilService.get_laoshi(rs.getInt("laoshi_id")));
kebiaoList.add(kebiao);
}
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
mydb.closed();
req.setAttribute("kebiaoList", kebiaoList);
req.getRequestDispatcher("admin/kebiao/kebiaoMana.jsp").forward(req, res);
}
public void kebiaoDel(HttpServletRequest req, HttpServletResponse res) {
String sql = "update t_kebiao set del='yes' where id=" + Integer.parseInt(req.getParameter("id"));
Object[] params = {};
DB mydb = new DB();
mydb.doPstm(sql, params);
mydb.closed();
req.setAttribute("message", "操作成功");
req.setAttribute("path", "kebiao?type=kebiaoMana");
String targetURL = "/common/success.jsp";
dispatch(targetURL, req, res);
}
public void kebiaoMana_tea(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
List kebiaoList = new ArrayList();
String sql = "select * from t_kebiao where del='no' and laoshi_id=?";
Object[] params = {((Tlaoshi) (req.getSession().getAttribute("laoshi"))).getId()};
DB mydb = new DB();
try {