package com.course;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class CourseSvlt extends HttpServlet{
//响应get请求
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
//获得课程ID
String cour_id =req.getParameter("id");
int success = 0;
//获取请求中的参数
String action = action = req.getParameter("action");
course cour = null;
String message="";
//如果请求中包含新建课程参数
if ("new".equalsIgnoreCase(action)) {
//调用新建课程方法
cour = doNew(req,res);
//并将新建课程存储在request上下文中,然后转向getcourse.jsp页面
sendBean(req, res, cour, "/getcourse.jsp");
}
//如果请求中包含更新课程参数
if ("update".equalsIgnoreCase(action)) {
try{
// 调用更新课程方法
cour = doUpdate(req,res, cour_id);
//并将更新后的课程存储在request上下文中,然后转向getcourse.jsp页面
sendBean(req,res,cour,"/getcourse.jsp");
}
catch(SQLException e){}
}
//如果请求中包含删除课程参数
if ("delete".equalsIgnoreCase(action)) {
try{
//调用删除课程方法
success = doDelete(cour_id);
}
catch(SQLException e){}
if (success != 1) {
doError(req, res, "CourseSvlt: Delete unsuccessful. Rows affected: " + success);
} else {
res.sendRedirect("http://localhost:8080/test/getcourse.jsp");
}}
}
//新建课程方法定义
public course doNew(HttpServletRequest req,HttpServletResponse res )
throws ServletException,IOException{
course cour= new course();
String cour_id=req.getParameter("id");
int mark;
String name=new String(req.getParameter("name").getBytes("ISO8859_1"));
try{
mark= Integer.parseInt(req.getParameter("mark"));
}catch(NumberFormatException e){mark=0;}
String dep=new String (req.getParameter("dep").getBytes("ISO8859_1"));
String prepare =req.getParameter("prepare");
if(isTrue(req,res,cour_id,name) && hasLogin(req,res,cour_id) && isCompare(prepare,dep,req,res)){
cour.setId(cour_id);
cour.setName(name);
cour.setDep(dep);
cour.setPrepare(prepare);
cour.setMark(mark);
cour.addCourse();
}
return cour;
}
//判断课程是否与其预修课属于同一个系
public boolean isCompare(String prepare,String dep,
HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException{
boolean f=true;
String tempDep=null;
String message=null;
course cour= new course();
if( !prepare.equalsIgnoreCase("0") ){
tempDep=cour.getPrepareDep(prepare) ;
if(tempDep.equals("public"))
return true;
if(dep.equalsIgnoreCase(tempDep))
f=true;
else {
f=false;
message="错误,课程所在系与预修课所在系不一致!";
doError(req,res,message);
}}
return f;
}
//更新课程信息
public course doUpdate(HttpServletRequest req,HttpServletResponse res , String id)
throws ServletException,IOException,SQLException {
course cour = new course();
String name=new String(req.getParameter("name").getBytes("ISO8859_1"));
int mark = Integer.parseInt(req.getParameter("mark"));
String dep = req.getParameter("dep");
String prepare = req.getParameter("prepare");
if(isTrue(req,res,id,name) && isCompare(prepare,dep,req,res)){
cour.setName(name);
cour.setMark(mark);
cour.setDep(dep);
cour.setPrepare(prepare);
cour.updateCourse(id);}
return cour;
}
//删除课程
public int doDelete(String id) throws SQLException {
int num=0;
course cour=new course();
num=cour.deleteCourse(id);
return num;
}
//保存课程信息的JavaBean到request上下文中
public void sendBean(HttpServletRequest req, HttpServletResponse res,
course cour, String target)
throws ServletException, IOException {
req.setAttribute("cour", cour);
RequestDispatcher rd = getServletContext().getRequestDispatcher(target);
rd.forward(req, res);
}
//错误处理方法
public void doError(HttpServletRequest req,
HttpServletResponse res,
String str)
throws ServletException, IOException {
req.setAttribute("problem", str);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/errorpage.jsp");
rd.forward(req, res);
}
//判断课程是否被注册过
public boolean hasLogin(HttpServletRequest req, HttpServletResponse res,String id)
throws ServletException, IOException{
boolean f=true;
String message="对不起,该课程号已经被注册过了!";
course cour= new course();
f= cour.hasLogin(id);
if(f==false){
doError(req,res,message);
}
return f;
}
//判断课程注册是否成功
public boolean isTrue(HttpServletRequest req, HttpServletResponse res,
String id,String name)
throws ServletException, IOException {
boolean f=true;
String message ="";
if(id==null || id.equals("")) {
f=false;
message="错误,课程号不能为空!";
doError(req,res,message); }
if(name==null || name.equals("")) {
f=false;
message="课程名不能为空,请重新填写!";
doError(req,res,message); }
return f;
}
//响应post请求
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
doGet(req, res);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
计算机毕业设计项目源码:毕业设计课程管理系统,jsp+SQLServer实现.rar (60个子文件)
CourseManagement
.classpath 340B
.mymetadata 321B
src
com
course
course.java 3KB
StudentLoginSvlt.java 5KB
teacher.java 2KB
checkEnrol.java 3KB
login_confirm.java 3KB
TeacherSvlt.java 5KB
StudentSvlt.java 6KB
ClassSvlt.java 6KB
MarkSvlt.java 4KB
CourseSvlt.java 6KB
sqlBean.java 2KB
classp.java 4KB
determine.java 3KB
student.java 3KB
WebRoot
checkmark.jsp 1KB
updatetea.jsp 1KB
updatestu_confirm.jsp 1KB
addstudent.jsp 2KB
getStudent.jsp 2KB
WEB-INF
classes
com
course
TeacherSvlt.class 5KB
MarkSvlt.class 5KB
teacher.class 3KB
StudentLoginSvlt.class 5KB
login_confirm.class 4KB
student.class 3KB
course.class 4KB
determine.class 3KB
checkEnrol.class 4KB
CourseSvlt.class 6KB
sqlBean.class 3KB
ClassSvlt.class 6KB
StudentSvlt.class 5KB
classp.class 5KB
lib
web.xml 2KB
updatecour.jsp 2KB
choosestu.jsp 1KB
admin.jsp 938B
updatestu.jsp 2KB
DisplayCourse.jsp 2KB
teacher.jsp 650B
marking.jsp 965B
score.jsp 2KB
AddClass.jsp 3KB
updateinformation.jsp 1KB
public.jsp 1KB
updateClass.jsp 3KB
getClass.jsp 2KB
errorpage.jsp 781B
student.jsp 920B
displaystu.jsp 2KB
addteacher.jsp 1KB
getcourse.jsp 1KB
getteacher.jsp 1KB
META-INF
MANIFEST.MF 39B
Addcourse.jsp 2KB
login.jsp 7KB
.project 1KB
.myeclipse
db
backup_ClassDB.BAK 1.21MB
共 60 条
- 1
资源评论
mylife512
- 粉丝: 1461
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功