大家好,又见面了,我是你们的朋友全栈君。
delete(String stuno)
方法,最后跳转至删除成功与否界面<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>学生登录</title>
</head>
<body>
<form name="postForm" action="LoginStuSuccess.jsp" method="post">
<p>账号 :<input type="text" name="stuno" /></p>
<p>密码 :<input type="password" name="password" /></p>
<input type="submit" value="登录" />
</form>
</body>
</html>
<%@ page language="java" import="java.util.*,StudentScore.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>学生登录成功</title>
</head>
<body>
<form name="postForm" action="MenuStudent.jsp" method="post">
<%
StudentDao sdao = new StudentDaoJDBC();
String no = request.getParameter("stuno");
int stuno = Integer.parseInt(no);
String password = request.getParameter("password");
if(sdao.login(stuno,password)!=1){
response.sendRedirect("StudentLogin.jsp");
}
else
{
%>
<td>学号:<input type="text" id="a" name="stuno" value=<%=no%>></td>
<p>登陆成功!</p>
<input type="submit" value="Menu" />
<%
}
%>
</form>
</body>
</html>
@Override
public int login(int no, String password) {
// TODO Auto-generated method stub
int result=-1;
Connection conn = null;
PreparedStatement pstat = null;
ResultSet rs = null;
String sql = "select * from students where stuno=?";//表中有id和name这列
try {
conn = JDBCUtil.getConnection();
pstat = conn.prepareStatement(sql);
pstat.setInt(1,no);
rs = pstat.executeQuery();
int stu = 0;
String stupassword=null;
while(rs.next()){
stupassword=rs.getString("password");
stu=rs.getInt("stuno");
}
if(stu>0){
if(stupassword.equals(password)){
System.out.println("登录成功!");
result = 1;
}
else{
System.out.println("登录失败,密码错误!");
}
}else {
System.out.println("登录失败,学号不存在!");
}
}catch (SQLException sqle) {
sqle.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}finally{
JDBCUtil.realeaseAll(rs,pstat, conn);
}
return result;
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> 菜单选项</title>
</head>
<body>
<form name="fm" method="post">
<p>功能选择</p>
<p>1.录入学生成绩,点击<input type="button" name="btn2" onclick="document.fm.action='EnterStudentScore.jsp';document.fm.submit();"
value="录入"/></p>
<p>2.删除学生信息,点击<input type="button" name="btn1" onclick="document.fm.action='Delete.jsp';document.fm.submit();"
value="删除"/></p>
<p>3.修改学生信息,点击<input type="button" name="btn2" onclick="document.fm.action='UpdateView.jsp';document.fm.submit();"
value="修改"/></p>
<p>4.查找学生信息,点击<input type="button" name="btn2" onclick="document.fm.action='findStudent.jsp';document.fm.submit();"
value="查找"/></p>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> 老师菜单</title>
</head>
<body>
<form name="fm" method="post">
<p>功能选择</p>
<p>1.录入学生成绩,点击<input type="button" name="btn2" onClick="document.fm.action='MenuCourse.jsp';document.fm.submit();"
value="录入"/></p>
<p>2.删除学生信息,点击<input type="button" name="btn1" width="100" heigth="20" onClick="document.fm.action='Delete.jsp';document.fm.submit();"
value="删除"/></p>
<p>3.修改学生信息,点击<input type="button" name="btn2" onClick="document.fm.action='UpdateView1.jsp';document.fm.submit();"
value="修改"/></p>
<p>4.查找学生信息,点击<input type="button" name="btn2" onClick="document.fm.action='findStudent.jsp';document.fm.submit();"
value="查找"/></p>
<p>5.所有学生信息,点击<input type="button" name="btn2" onClick="document.fm.action='ShowStudentMessage.jsp';document.fm.submit();"
value="导出"/></p>
</form>
</body>
</html>
@Override
public int delete(String no) {
// TODO Auto-generated method stub
Connection conn = null;
Statement st= null;
ResultSet resultset=null;
String sql = "delete from students where stuno="+no;
int result = -1;
try {
conn = JDBCUtil.getConnection();
st = conn.createStatement();
int i=st.executeUpdate(sql);
}catch (SQLException sqle) {
sqle.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}finally{
JDBCUtil.realeaseAll(null,st, conn);
}
return result;
}
<%@ page language="java" import="java.util.*,StudentScore.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>删除学生</title>
</head>
<body>
<form name="postForm" action="DeleteSuccess.jsp" method="post">
<p>请输入需要删除的学生学号</p>
<p>
学号:<input type="text" name="stuno" />
</p>
<input type="submit" value="Delete" />
</form>
</body>
</html>
<%@ page language="java" import="java.util.*,StudentScore.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>删除成功</title>
</head>
<body>
<form name="postForm" action="MenuTeacher.jsp" method="post">
<%
StudentDao sdao = new StudentDaoJDBC();
String no = request.getParameter("stuno");
int s = sdao.delete(no);
%>
<p>删除成功!返回菜单</p>
<input type="submit" value="MENU" />
</form>
</body>
</html>
通过这次课设,对数据库,Dao,JDBC等认识加深了很多,不仅如此,还积累了一些课外的新知识;虽然过程中碰到许多令人崩溃和无语的问题,,在jsp与Java还有一些不熟悉的地方,所幸最终大部分问题都能解决;还有重要的一点是团队协作很重要,有时候你忽略的小问题别人一眼就能发现,虽然我的能力不够好,但是到最后看到自己的代码(虽然不多)能在整个项目中运行还是很激动很开心的;遗憾的是时间紧,技术弱,没能把想法更加完善出来。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/154395.html原文链接:https://javaforall.cn