请登录后探索更多精彩内容!
选课管理大概就是考验新手实力的实力的时候了。由于对JavaBean不太了解,基本都是直接把链接数据库代码写在JSP里面了。仅供参考。
首页课程选课模块:显示所有课程信息和选课功能。
课程信息显示jsp代码
<%@page import="javax.mail.Session"%> <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@ page import="java.sql.*"%> <!DOCTYPE HTML> <!------------- 所有选课数据显示界面 ----------------> <html> <head> <title>My JSP 'classtable.jsp' starting page</title> <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE11" /> <link rel="stylesheet" type="text/css" href="css/style.css"> </head> <% String url = "jdbc:mysql://localhost:3306/user?useUnicode=true&characterEncoding=UTF8"; //数据库名 String username = "root"; //数据库用户名 String password = ""; //数据库用户密码 Connection conn = null; //连接状态 Statement stmt = null; ResultSet rs = null; Class.forName("com.mysql.jdbc.Driver"); conn=DriverManager.getConnection(url, username, password); stmt = conn.createStatement(); //查询语句 rs = stmt.executeQuery("SELECT classid,classname,point,teacher,place,classtime FROM classsql;"); %> <body bgcolor="#d9e1e8"> <div> <form action="myclass.jsp" method="post"> <table > <caption><h1>选课列表<h1></caption> <tr> <th>课程号</th> <th>课程名</th> <th>学分</th> <th>老师</th> <th>地点</th> <th>时间</th> <th>操作</th> </tr> <%while(rs.next()){ %> <tr> <!-- 学号 --> <td><%=rs.getString("classid") %></td> <!-- 姓名 --> <td><%=rs.getString("classname") %></td> <!-- 学分 --> <td><%=rs.getString("point") %></td> <!-- 老师 --> <td><%=rs.getString("teacher") %></td> <!-- 地点 --> <td><%=rs.getString("place") %></td> <!-- 时间 --> <td><%=rs.getString("classtime") %></td> <td> <a href="addclass_process.jsp?userid=<%=rs.getString("classid")%>">选课 </a> </td> </tr> <%} rs.close(); conn.close(); %> </table> </form> </div> </body> </html>
选课处理过程jsp代码
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ page import="java.sql.*"%> <!DOCTYPE html> <!------------- 选课成功过程 -----------------> <html> <head> <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE11" /> <title>Insert title here</title> </head> <body> <% String url = "jdbc:mysql://localhost:3306/user?useUnicode=true&characterEncoding=UTF8"; //数据库名 String username = "root"; //数据库用户名 String password = ""; //数据库用户密码 Connection conn = null; //连接状态 Statement stmt = null; Statement stm = null; ResultSet rs = null; Statement stmm = null; ResultSet rsm = null; request.setCharacterEncoding("utf-8"); String userid=request.getParameter("userid"); String name = (String)session.getAttribute("u"); Class.forName("com.mysql.jdbc.Driver"); conn=DriverManager.getConnection(url, username, password); stmt = conn.createStatement(); //查询语句 rs = stmt.executeQuery("SELECT classid,classname,point,teacher,place,classtime FROM classsql where classid='"+userid+"';"); stm = conn.createStatement(); stmm = conn.createStatement(); rsm = stmm.executeQuery("SELECT classid,classname,point,teacher,place,classtime FROM myclasssql where classid='"+userid+"';"); while(rs.next()) { if(rsm.next()){ out.println("<script language='javascript'>alert('你已经选过了!');window.location.href='classtable.jsp';</script>"); } else{ stm.executeUpdate("insert into myclasssql(stuname,classid,classname,point,teacher,place,classtime) values('"+name+"','"+rs.getString(1)+"','"+rs.getString(2)+"','"+rs.getString(3)+"','"+rs.getString(4)+"','"+rs.getString(5)+"','"+rs.getString(6)+"');"); out.println("<script language='javascript'>alert('选课成功!');window.location.href='classtable.jsp';</script>"); } } %> </body> </html>
我的选课模块:显示已选课程所有信息和提供退课功能。
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ page import="java.sql.*"%> <!DOCTYPE html> <!------ 我的选课 -------> <html> <head> <title>我的选课</title> </head> <link rel="stylesheet" type="text/css" href="css/style.css"> <body> <% //连接数据库代码 String url = "jdbc:mysql://localhost:3306/user?useUnicode=true&characterEncoding=UTF8"; //数据库名 String username = "root"; //数据库用户名 String password = ""; //数据库用户密码 Connection conn = null; //连接状态 Statement stmt = null; ResultSet rs = null; String name = (String)session.getAttribute("u"); Class.forName("com.mysql.jdbc.Driver"); conn=DriverManager.getConnection(url, username, password); stmt = conn.createStatement(); rs = stmt.executeQuery("SELECT classid,classname,point,teacher,place,classtime FROM myclasssql where stuname='"+name+"';"); //查询语句 %> <body bgcolor="#d9e1e8"> <div> <form action="" method="post"> <table > <!-- 表头 --> <caption><h1>已选课程<h1></caption> <tr> <th>课程号</th> <th>课程名</th> <th>学分</th> <th>老师</th> <th>地点</th> <th>时间</th> <th>操作</th> </tr> <%while(rs.next()){ %> <tr> <!-- 课程号 --> <td><%=rs.getString("classid") %></td> <!-- 课程名 --> <td><%=rs.getString("classname") %></td> <!-- 学分 --> <td><%=rs.getString("point") %></td> <!-- 老师 --> <td><%=rs.getString("teacher") %></td> <!-- 地点 --> <td><%=rs.getString("place") %></td> <!-- 时间 --> <td><%=rs.getString("classtime") %></td> <!-- 退课功能 --> <td><a href="deleteclass.jsp?classid=<%=rs.getString("classid")%>">退课 </a></td> </tr> <%} rs.close(); conn.close(); %> </table> </form> </div> </body> </html>
退课处理过程jsp代码
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ page import="java.sql.*"%> <!DOCTYPE html> <!-------------- 退课过程 ------------------> <html> <head> <title>Insert title here</title> <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE11" /> </head> <body> <% String url = "jdbc:mysql://localhost:3306/user?useUnicode=true&characterEncoding=UTF8"; //数据库名 String username = "root"; //数据库用户名 String password = ""; //数据库用户密码 Connection conn = null; //连接状态 Statement stmt = null; Statement stm = null; ResultSet rs = null; String classid=request.getParameter("classid");//接收传递的课程号 String name = (String)session.getAttribute("u");//获取当前用户名 Class.forName("com.mysql.jdbc.Driver"); conn=DriverManager.getConnection(url, username, password); stmt = conn.createStatement(); //查询语句 //执行修改SQL语句 stmt.executeUpdate("delete FROM myclasssql where classid='"+classid+"' and stuname='"+name+"';"); //执行完毕输出弹窗 提示 out.println("<script language='javascript'>alert('退课成功!');window.location.href='myclass.jsp';</script>"); %> </body> </html>
暂无评论
请先登录后发表评论!
暂无评论