package com.course;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class StudentSvlt extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
//获得学生ID
String stu_id =req.getParameter("id");
int success = 0;
// 获取请求中的参数
String action = action = req.getParameter("action");
student stu = null;
String message="";
//如果请求中包含新建学生参数
if ("new".equalsIgnoreCase(action)) {
// 调用新建学生方法
stu = doNew(req,res);
// 并将新建学生存储在request上下文中,然后转向getStudent.jsp页面
sendBean(req, res, stu, "/getStudent.jsp");
}
// 如果请求中包含修改学生参数
if ("update".equalsIgnoreCase(action)) {
try{
// 调用修改学生信息方法
stu = doUpdate(req,res, stu_id);
// 并将修改后的学生信息存储在request上下文中,然后转向getStudent.jsp页面
sendBean(req,res,stu,"/getStudent.jsp");
}
catch(SQLException e){}
}
// 如果请求中包含删除学生参数
if ("delete".equalsIgnoreCase(action)) {
try{
//调用删除学生方法
success = doDelete(stu_id);
}
catch(SQLException e){}
if (success != 1) {
doError(req, res, "StudentSvlt: Delete unsuccessful. Rows affected: " + success);
} else {
res.sendRedirect("http://localhost:8080/test/getStudent.jsp");
}
}
}
//新建学生方法定义
public student doNew(HttpServletRequest req,HttpServletResponse res )
throws ServletException,IOException{
student stu= new student();
String stu_id=req.getParameter("id");
String name=new String(req.getParameter("name").getBytes("ISO8859_1"));
String password= req.getParameter("password");
String dep=new String (req.getParameter("dep").getBytes("ISO8859_1"));
String sex = new String(req.getParameter("sex").getBytes("ISO8859_1"));
String jiguan = new String(req.getParameter("jiguan").getBytes("ISO8859_1"));
if(isTrue(req,res,stu_id,name,password) && hasLogin(req,res,stu_id)){
stu.setId(stu_id);
stu.setName(name);
stu.setPassword(password);
stu.setDep(dep);
stu.setSex(sex);
stu.setJiguan(jiguan);
stu.addStudent(); }
return stu;
}
//更新学生信息方法
public student doUpdate(HttpServletRequest req,HttpServletResponse res , String id)
throws ServletException,IOException,SQLException {
student stu = new student();
String name=new String(req.getParameter("name").getBytes("ISO8859_1"));
String password = req.getParameter("password");
String dep = new String(req.getParameter("dep").getBytes("ISO8859_1"));
String sex = new String(req.getParameter("sex").getBytes("ISO8859_1"));
String jiguan = new String(req.getParameter("jiguan").getBytes("ISO8859_1"));
if(isTrue(req,res,id,name,password)){
stu.setId(id);
stu.setName(name);
stu.setPassword(password);
stu.setDep(dep);
stu.setSex(sex);
stu.setJiguan(jiguan);
stu.updateStudent();}
return stu;
}
//删除学生方法
public int doDelete(String id) throws SQLException {
int num=0;
student stu=new student();
num=stu.deleteStudent(id);
return num;
}
//保存学生信息的JavaBean到request上下文中
public void sendBean(HttpServletRequest req, HttpServletResponse res,
student stu, String target)
throws ServletException, IOException {
req.setAttribute("stu", stu);
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="对不起,该学生号已经被注册过了!";
student stu= new student();
f= stu.hasLogin(id);
if(f==false){
doError(req,res,message);
}
return f;
}
//判断学生注册是否成功
public boolean isTrue(HttpServletRequest req, HttpServletResponse res,
String id,String name,String password)
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); }
if(password==null || password.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+servlet+java)
共66个文件
jsp:26个
class:14个
java:14个
需积分: 15 26 下载量 192 浏览量
2013-01-26
14:11:40
上传
评论 1
收藏 166KB RAR 举报
温馨提示
学分管理系统,包括学生管理,教师管理,学分管理。实现增删改查等功能!工程包括14给类文件和27个jsp文件,和数据库备份文件,资料齐全,无错。
资源推荐
资源详情
资源评论
收起资源包目录
CourseManagement.rar (66个子文件)
CourseManagement
.project 2KB
db
backup_ClassDB.BAK 1.21MB
.mymetadata 321B
src
com
course
TeacherSvlt.java 5KB
course.java 3KB
teacher.java 2KB
determine.java 3KB
student.java 3KB
StudentLoginSvlt.java 5KB
classp.java 4KB
ClassSvlt.java 5KB
sqlBean.java 3KB
login_confirm.java 3KB
StudentSvlt.java 6KB
checkEnrol.java 3KB
MarkSvlt.java 4KB
CourseSvlt.java 5KB
WebRoot
addstudent.jsp 2KB
choosestu.jsp 1KB
student.jsp 920B
getteacher.jsp 1KB
WEB-INF
classes
com
course
teacher.class 3KB
classp.class 5KB
sqlBean.class 3KB
TeacherSvlt.class 5KB
course.class 4KB
checkEnrol.class 4KB
login_confirm.class 4KB
CourseSvlt.class 6KB
StudentLoginSvlt.class 5KB
StudentSvlt.class 5KB
ClassSvlt.class 6KB
MarkSvlt.class 5KB
determine.class 3KB
student.class 3KB
lib
web.xml 2KB
score.jsp 2KB
updateinformation.jsp 1KB
displaystu.jsp 2KB
admin.jsp 938B
getcourse.jsp 1KB
addteacher.jsp 1KB
AddClass.jsp 3KB
updateClass.jsp 3KB
Addcourse.jsp 2KB
getStudent.jsp 2KB
getClass.jsp 2KB
META-INF
MANIFEST.MF 39B
checkmark.jsp 1KB
marking.jsp 965B
login.jsp 7KB
updatetea.jsp 1KB
errorpage.jsp 781B
DisplayCourse.jsp 2KB
updatecour.jsp 2KB
teacher.jsp 650B
public.jsp 1KB
updatestu_confirm.jsp 1KB
updatestu.jsp 2KB
.myeclipse
.settings
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.common.project.facet.core.xml 252B
org.eclipse.jdt.core.prefs 334B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.common.component 486B
.jsdtscope 500B
.classpath 507B
共 66 条
- 1
资源评论
YiWait
- 粉丝: 25
- 资源: 37
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 论文(最终)_20240430235101.pdf
- 基于python编写的Keras深度学习框架开发,利用卷积神经网络CNN,快速识别图片并进行分类
- 最全空间计量实证方法(空间杜宾模型和检验以及结果解释文档).txt
- 5uonly.apk
- 蓝桥杯Python组的历年真题
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 前端开发技术实验报告:内含4四实验&实验报告
- Highlight Plus v20.0.1
- 林周瑜-论文.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功