import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class CourseSvlt extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
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);
sendBean(req, res, cour, "/getcourse.jsp");
}
if ("update".equalsIgnoreCase(action)) {
try{
cour = doUpdate(req,res, cour_id);
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;
}
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;
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
doGet(req, res);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
校开发一学生课绩管理系统,该系统由登陆模块,学生模块,教师模块,管理员模块,四部分组成 本系统采用Servlet+Jsp+JavaBean+SQL2000 设计方式,其中Servlet担当主要逻辑控制,通过接受Jsp传来的用户请求,调用以及初始化JavaBean,在通过Jsp传到客户端,本系统中SqlBean担当主要的与数据库的连接与通信,JavaBean在本系统中主要担当配合Jsp以及Servlet来完成用户的请求,而Jsp主要担当接受与响应客户端。
资源推荐
资源详情
资源评论
收起资源包目录
学生课绩管理系统sql_server.rar (46个子文件)
学生课绩管理系统sql_server
学生课绩管理系统(升级版).rar 374KB
学生课绩管理系统.doc 26KB
test(jsp+servlet+javaBean+sql_server)
login.jsp 7KB
updatestu_confirm.jsp 1KB
Addcourse.jsp 2KB
teacher.jsp 650B
updatestu.jsp 2KB
errorpage.jsp 781B
WEB-INF
web.xml 2KB
work
tmp
jsp
lib
classes
TeacherSvlt.java 5KB
student.java 3KB
login_confirm.java 3KB
course.java 3KB
CourseSvlt.java 5KB
sqlBean.java 2KB
StudentLoginSvlt.java 4KB
checkEnrol.java 3KB
MarkSvlt.java 4KB
teacher.java 2KB
ClassSvlt.java 5KB
StudentSvlt.java 5KB
classp.java 4KB
determine.java 2KB
marking.jsp 965B
choosestu.jsp 1KB
addstudent.jsp 2KB
student.jsp 920B
admin.jsp 949B
getcourse.jsp 1KB
updateClass.jsp 3KB
updatetea.jsp 1KB
public.jsp 1KB
updateinformation.jsp 1KB
score.jsp 2KB
addteacher.jsp 1KB
updatecour.jsp 2KB
updateStudent.jsp 1KB
checkmark.jsp 1KB
displaystu.jsp 2KB
getteacher.jsp 1KB
getStudent.jsp 2KB
getClass.jsp 2KB
DisplayCourse.jsp 2KB
AddClass.jsp 3KB
backup_ClassDB.BAK 1.21MB
系统结构图.doc 937KB
共 46 条
- 1
资源评论
- huangooxs2015-03-18还好,适合初学者!
itsztw
- 粉丝: 7
- 资源: 30
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功