package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import dao.DepartDao;
import entity.Departinfo;
public class DepartServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public DepartServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* 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. <br>
*
* 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 {
//获取修改页面上每个输入框里面的值
request.setCharacterEncoding("gb2312");
response.setCharacterEncoding("gb2312");
String sper=request.getParameter("oper");
if(sper.equals("1")){
UpdateServelet(request,response);
}
else if(sper.equals("2")){
DeleteServelet(request, response);
}
else if(sper.equals("3")){
AddServelet(request, response);
}
// else if(sper.equals("4")){
// BackServelet(request, response);
// }
else if(sper.equals("5")){
QueryoneServlet(request, response);
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
public void UpdateServelet(HttpServletRequest request, HttpServletResponse response) throws IOException{//修改部门信息
//编码
request.setCharacterEncoding("gb2312");
response.setCharacterEncoding("gb2312");
//获取页面上输入的值
String deid=request.getParameter("id"); //获取编号
String deno=request.getParameter("number"); //获取输入的部门编号
String dename=request.getParameter("name"); //获取输入的部门名称
String depfor=request.getParameter("select");//获取选中的上级部门名称
//创建dao和实体对象
DepartDao depdao=new DepartDao();
Departinfo depinfo=new Departinfo();
Departinfo depinfo1=new Departinfo();
//通过上级部门名称获取上级部门编号
depinfo1=depdao.QueryByName(depfor); //通过对获取的上级部门名称查询出一个实体对象depinfo1
String forward=depinfo1.getDepart_no()+""; //获取depinfo1的部门编号
depfor=forward+deno; //将获取的部门编号与输入的部门编号(2个字符串)进行连接成depfor
//判断新增加的部门编号depfor在数据库中是否存在
ArrayList list=new ArrayList();
Departinfo depin=new Departinfo();
DepartDao depDao=new DepartDao();
list=depDao.QueryAll(); //对数据库进行查询
//判断查询到的实体的部门编号是否与新增的部门编号depfor相等
for(int i=0;i<list.size();i++){
depin=(Departinfo)list.get(i); //通过i值获取对应的实体
if(Integer.parseInt(depfor)==depin.getDepart_no()){//当查询到的实体的部门编号与新增的部门编号depfor相等时,直接返回不执行后面的语句
//response.sendRedirect("error.jsp");
return;
}
}
//当查询完数据库里面存在的所有部门编号与新增的部门编号不相同的时候执行下面的代码,进行修改
//将获得的值放入实体对象depinfo里面
depinfo.setDepart_id(Integer.parseInt(deid));
depinfo.setDepart_no(Integer.parseInt(depfor));//修改后的部门编号
depinfo.setDepart_name(dename);//修改后的部门名称
depinfo.setDepart_forward(Integer.parseInt(forward));//获取的上级部门编号
//将实体类放入DepartDao里面让其对数据库进行更新
boolean result= depdao.UpdateDepart(depinfo);
if(result){//如果修改成功跳转到显示所有信息界面
response.sendRedirect("web/depart_manage/departlist.jsp");
}
else{//如果修改失败,跳转到错误页面
response.sendRedirect("../error.jsp");
}
}
public void DeleteServelet(HttpServletRequest request, HttpServletResponse response) throws IOException{//删除部门信息
String sid=request.getParameter("id");//获取需要删除的编号
//创建dao与实体
DepartDao depdao=new DepartDao();
Departinfo depinfo=new Departinfo();
depinfo=depdao.QueryById(sid);//通过获取的编号进行查询并得到对象depinfo
int count = 0;
ArrayList list=new ArrayList();
list=depdao.QueryAll();//对数据库里面的数据进行全部查询,并放到数组list里面
for(int i=0;i<list.size();i++){
Departinfo depin=new Departinfo();
depin=(Departinfo)list.get(i);//将数组中每一个值存入一个实体depin对象里面
if(depin.getDepart_forward()==depinfo.getDepart_no()){//如果要删除的编号下的当前实体的部门编号存在与查询到的实体depin的上级部门编号相同的话,对count进行累加
count++;
}
}
if(count > 0) {//如果count的值大于0的话说明要删除的部门存在下级部门则该部门不能进行删除跳转到错误页面
response.sendRedirect("error1.jsp");
} else {//如果count值依然为0的话说明该部门不存在下级部门可以进行删除操作
boolean result=depdao.deletdepart(sid);//执行dao里面的删除方法
if(result){//删除成功
response.sendRedirect("web/depart_manage/departlist.jsp");
}
else{//删除失败,跳转到错误页面。
response.sendRedirect("error1.jsp");
}
}
}
public void AddServelet(HttpServletRequest request, HttpServletResponse response) throws IOException{//增加部门信息
//编码
request.setCharacterEncoding("gb2312");
response.setCharacterEncoding("gb2312");
//获取页面上输入的值
String deno=request.getParameter("no");//获取输入的部门编号
String dename=request.getParameter("name");//获取输入的部门名称
String depfor=request.getParameter("select");//获取上级部门名称
//System.out.println(depfor);
if(deno!=""&&dename!=""&&depfor!=""){//如果从输入框中获取的2个值都不为空的时候则执行下面的代码
//创建dao和实体对象
DepartDao depdao=new DepartDao();
Departinfo depinfo=new Departinfo();
Departinfo depinfo1=new Departinfo();
//通过上级部门名称获取上级部门编号
depinfo1=depdao.QueryByName(depfor);//通过选择获取的部门名称查询该部门的部门信息
String forward=depinfo1.getDepart_no()+"";//获取查询到的depinfo1的部门编号
depfor=forward+deno;//将输入的部门编号deno与获取到的上级的部门编号forward(它们都为字符串)进行连接
//System.out.println(depfor);
ArrayList list=new ArrayList();
Departinfo depin=new Departinfo();
DepartDao depDao=new DepartDao();
list=depDao.QueryAll();//查询数据库中所有的部门信息,并放入到数组list中
for(int i=0;i<list.size();i++){
depin=(Departinfo)list.get(i);//把获取的每一条部门信息放入实体对象depin中去
if(Integer.parseInt(depfor)==depin.getDepart_no()){//如果查询到的depin的部门编号与新增的部门编号相同的话,则直接返回不执行后面的代码
response.sendRedirect("error.jsp");//跳转到错误页面
return;
}
}
//如果查询到的depin的部门编号与新增的部门编号不相同的话,则将获得的值放入实体对象depinfo里面
depinfo.setDepart_no(Integer.parseInt(depfor));
depinfo.setDepart_name(dename);
depinfo.setDepart_forward(Integer.parseInt(forward));
//将实体类放入DepartDao里面让其对数据库进行�
没有合适的资源?快使用搜索试试~ 我知道了~
cms.rar_jsp servlet cms_班级管理系统
共250个文件
jsp:65个
class:47个
java:47个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 176 浏览量
2022-09-24
02:36:56
上传
评论
收藏 1.36MB RAR 举报
温馨提示
这是一个班级管理系统,用的servlet和JSP写的.....
资源推荐
资源详情
资源评论
收起资源包目录
cms.rar_jsp servlet cms_班级管理系统 (250个子文件)
scoreDao.class 7KB
MoralDAO.class 6KB
DBUtil.class 6KB
DepartDao.class 6KB
UserDAO.class 6KB
DepartServlet.class 5KB
CommmentDao.class 5KB
GrochServlet.class 5KB
ClassServlet.class 5KB
MoralServlet.class 5KB
MonInfoDao.class 5KB
StudentDAO.class 5KB
GroupServlet.class 5KB
scoreservlet.class 5KB
ClassMoneyServlet.class 4KB
UserServlet.class 4KB
Studentservlet.class 4KB
AttendanceServlet.class 4KB
GrochDAO.class 4KB
GroupDAO.class 4KB
ScoretDao.class 3KB
CourseServlet.class 3KB
AttendanceDAO.class 3KB
ClassInfoDAO.class 3KB
Stu_perfServlet.class 3KB
CourseDao.class 3KB
Student.class 3KB
StuDao.class 3KB
LoginServlet.class 2KB
Stu_prefDao.class 2KB
SelServlet.class 2KB
MonInfo.class 2KB
MonDao.class 2KB
CommentInfo.class 2KB
UserInfo.class 2KB
Moral.class 2KB
ClassInfo.class 1KB
Groch.class 1KB
Score.class 1KB
Departinfo.class 1KB
Attendance.class 1KB
Group.class 1KB
Stu_pref.class 1KB
Act.class 1KB
Course.class 982B
Role.class 975B
User.class 971B
.classpath 485B
org.eclipse.wst.jsdt.ui.superType.container 49B
style.css 12KB
menu.css 2KB
Thumbs.db 55KB
Thumbs.db 24KB
Thumbs.db 20KB
Thumbs.db 15KB
welcome.gif 57KB
logo.gif 13KB
bt_linkman.gif 2KB
login_btn_bg.gif 991B
ns_doc_mo.gif 582B
folderopen.gif 376B
folderclosed.gif 372B
folderclosed.gif 372B
bt_feedback.gif 322B
bt_confirm.gif 235B
bt_acti.gif 235B
bt_detail.gif 233B
bt_orders.gif 216B
bt_relay.gif 216B
bt_plan.gif 153B
bt_deal.gif 147B
folderopen.gif 129B
bt_yes.gif 117B
ns_doc_sel.gif 107B
msie_doc_sel.gif 107B
msie_doc_mo.gif 107B
bt_del.gif 90B
bt_edit.gif 87B
plus.gif 77B
doc.gif 76B
ns_doc.gif 76B
plustop.gif 76B
plusbottom.gif 76B
minus.gif 76B
minusbottom.gif 76B
msie_doc.gif 76B
plusonly.gif 75B
minusonly.gif 75B
minustop.gif 75B
join.gif 67B
line.gif 64B
joinbottom.gif 64B
jointop.gif 63B
blank.gif 56B
spacer.gif 43B
mywork.htm 319B
menu.html 5KB
login.html 2KB
year.html 1KB
week.html 1KB
共 250 条
- 1
- 2
- 3
资源评论
alvarocfc
- 粉丝: 109
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- C语言实现基于STM32F103RC的电子相册(原理图、PCB源文件、程序源码及制作).zip
- C语言实现基于stm32和mpu9250的usb hid键盘、鼠标、游戏控制器.zip
- SAP GUI for Windows 7.70 Patch16
- C语言实现基于物联网的户外环境检测装置(STM32、APP、WIFI).zip
- Models for ICM/MCM美赛常用模型.zip
- cef源码CEF全称Chromium Embedded Framework
- hbase分布式.rar
- vc 6.0简介.rar
- C语言实现智能家居专用-STM32 以太网开发板电路设计(开源带例程).zip
- 基于深度学习的分类.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功