学生成绩查询系统

  • 欢迎浏览
    • 项目目录
    • com.zz.action
    • com.zz.action.student
    • com.zz.action.test
    • com.zz.controller
    • com.zz.dao
    • com.zz.pojo
    • com.zz.util
    • src
    • db
    • lib
    • WEB-INF
    • WebContent
    • 效果图

欢迎浏览

你好!这一篇文章是为了巩固对前面知识,完成的练习。需要使用的知识:jsp,mysql,java
工具:c3p0数据库连接器。

项目目录

![项目目录](https://img-blog.csdnimg.cn/20191028084007862.png

com.zz.action

package com.zz.action;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;public interface Action {public void execute(HttpServletRequest request,HttpServletResponse response);
}

com.zz.action.student

QueryStudentInfoAction.java

package com.zz.action.student;import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import com.zz.action.Action;
import com.zz.dao.ScoreDao;
import com.zz.dao.StudentDao;
import com.zz.pojo.Score;
import com.zz.pojo.Student;public class QueryStudentInfoAction implements Action {private StudentDao studentDao;private ScoreDao scoreDao;public QueryStudentInfoAction() {studentDao = new StudentDao();scoreDao = new ScoreDao();}@Overridepublic void execute(HttpServletRequest request, HttpServletResponse response) {//下拉班级ArrayList<Student> slist = studentDao.getKindOfClassname();request.setAttribute("slist", slist);if(!request.getParameter("subject").equals("")&&request.getParameter("name").equals("")&&request.getParameter("classname").equals("所有班级")) {//按科目查找String subject = request.getParameter("subject");ArrayList<Score> list = scoreDao.getInfoBySub(subject);HashMap<Integer,Student> map = new HashMap<Integer,Student>();for (Score score: list) {int sid = score.getSid();Student student = studentDao.getStudentById(sid);map.put(sid, student);}request.setAttribute("list", list);request.setAttribute("map", map);try {request.getRequestDispatcher("/studentInfo.jsp").forward(request, response);return;} catch (ServletException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}else if(request.getParameter("subject").equals("")&&!request.getParameter("name").equals("")&&request.getParameter("classname").equals("所有班级")) {//按姓名查找String name = request.getParameter("name");int sid = studentDao.getIdByName(name);ArrayList<Score> list = scoreDao.getScoreBySid(sid);HashMap<Integer,Student> map = new HashMap<Integer,Student>();for (Score score: list) {int sdid = score.getSid();Student student = studentDao.getStudentById(sdid);map.put(sdid, student);}request.setAttribute("list", list);request.setAttribute("map", map);try {request.getRequestDispatcher("/studentInfo.jsp").forward(request, response);return;} catch (ServletException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}else if(request.getParameter("subject").equals("")&&request.getParameter("name").equals("")&&!request.getParameter("classname").equals("")) {//按班级查找String classname = request.getParameter("classname");if(classname.equals("所有班级")) {//查全部信息try {request.getRequestDispatcher("student-info.action").forward(request, response);return;} catch (ServletException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}else {ArrayList<Student> list = studentDao.getInfoByCname(classname);int size = list.size()-1;ArrayList<Score> scoreList = new ArrayList<Score>();int a = 0;for(a=0;a<=size;a++) {int b = list.get(a).getId();scoreList.addAll(scoreDao.getScoreBySid(b));}HashMap<Integer,Student> map = new HashMap<Integer,Student>();for (Score score: scoreList) {int sdid = score.getSid();Student student = studentDao.getStudentById(sdid);map.put(sdid, student);}request.setAttribute("list", scoreList);request.setAttribute("map", map);try {request.getRequestDispatcher("/studentInfo.jsp").forward(request, response);return;} catch (ServletException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}else if(!request.getParameter("subject").equals("")&&!request.getParameter("name").equals("")&&!request.getParameter("classname").equals("")) {//多条件查找if(request.getParameter("classname").equals("所有班级")) {String subject = request.getParameter("subject");String name = request.getParameter("name");int sid = studentDao.getIdByName(name);ArrayList<Score> list = scoreDao.getOnSidSubject(sid, subject);HashMap<Integer,Student> map = new HashMap<Integer,Student>();for (Score score: list) {int id = score.getSid();Student student = studentDao.getStudentById(id);map.put(id, student);}request.setAttribute("list", list);request.setAttribute("map", map);try {request.getRequestDispatcher("/studentInfo.jsp").forward(request, response);return;} catch (ServletException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}else{String subject = request.getParameter("subject");String name = request.getParameter("name");String classname = request.getParameter("classname");int sid = studentDao.getIdOnNameCName(name, classname);ArrayList<Score> list = scoreDao.getOnSidSubject(sid, subject);HashMap<Integer,Student> map = new HashMap<Integer,Student>();for (Score score: list) {int id = score.getSid();Student student = studentDao.getStudentById(id);map.put(id, student);}request.setAttribute("list", list);request.setAttribute("map", map);try {request.getRequestDispatcher("/studentInfo.jsp").forward(request, response);return;} catch (ServletException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}}}

StudentInfoAction.java

package com.zz.action.student;import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import com.zz.action.Action;
import com.zz.dao.ScoreDao;
import com.zz.dao.StudentDao;
import com.zz.pojo.Score;
import com.zz.pojo.Student;public class StudentInfoAction implements Action {private StudentDao studentDao;private ScoreDao scoreDao;public StudentInfoAction() {studentDao = new StudentDao();scoreDao = new ScoreDao();}@Overridepublic void execute(HttpServletRequest request, HttpServletResponse response) {//下拉班级ArrayList<Student> slist = studentDao.getKindOfClassname();request.setAttribute("slist", slist);//信息展示ArrayList<Score> list = scoreDao.getScore();HashMap<Integer,Student> map = new HashMap<Integer,Student>();for (Score score: list) {int sid = score.getSid();Student student = studentDao.getStudentById(sid);map.put(sid, student);}request.setAttribute("list", list);request.setAttribute("map", map);try {request.getRequestDispatcher("/studentInfo.jsp").forward(request, response);} catch (ServletException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}

com.zz.action.test

Test.java

package com.zz.action.test;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import com.zz.action.Action;public class Test implements Action{public Test() {}@Overridepublic void execute(HttpServletRequest request, HttpServletResponse response) {     }
}

com.zz.controller

package com.zz.controller;import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import com.zz.action.Action;public class ActionServlet extends HttpServlet {private static final long serialVersionUID = 1L;private Properties properties;public void init() {String file=Thread.currentThread().getContextClassLoader().getResource("config.properties").getFile();properties=new Properties();try {properties.load(new FileInputStream(file));} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}protected void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {doPost(request, response);}protected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {request.setCharacterEncoding("UTF-8");response.setCharacterEncoding("UTF-8");response.setContentType("text/html; charset=UTF-8");String struri=request.getRequestURI();struri=struri.substring(struri.lastIndexOf("/")+1);String className=properties.getProperty(struri);try {Action action = (Action) Class.forName(className).newInstance();action.execute(request,response);} catch (Exception e) {e.printStackTrace();}}}

com.zz.dao

ScoreDao.java

package com.zz.dao;import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;import com.zz.pojo.Score;
import com.zz.util.C3P0Utils;public class ScoreDao {public ArrayList<Score> getScore() {ArrayList<Score> list = new ArrayList<Score>();Connection con = null;Statement st = null;ResultSet rs = null;String sql = "select * from tbl_score";try {con = C3P0Utils.getConn();st = con.createStatement();rs = st.executeQuery(sql);while (rs.next()) {Score score = new Score();score.setId(rs.getInt("id"));score.setSubject(rs.getString("subject"));score.setScore(rs.getInt("score"));score.setSid(rs.getInt("sid"));list.add(score);}} catch (Exception e) {e.printStackTrace();} finally {C3P0Utils.closeJDBC(con, st, rs);}return list;}public ArrayList<Score> getOnSidSubject(int sid,String subject) {ArrayList<Score> list = new ArrayList<Score>();Connection conn = C3P0Utils.getConn();PreparedStatement psmt = null;ResultSet rs = null;try {                                                String sql = "select * from tbl_score where subject = ? and sid = ?";psmt = conn.prepareStatement(sql);psmt.setString(1, subject);psmt.setInt(2, sid);// 执行rs = psmt.executeQuery();while (rs.next()) {Score score = new Score();score.setId(rs.getInt("id"));score.setSubject(rs.getString("subject"));score.setScore(rs.getInt("score"));score.setSid(rs.getInt("sid"));list.add(score);} } catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();} finally {C3P0Utils.closeJDBC(conn, psmt, rs);}return list;}public ArrayList<Score> getInfoBySub(String subject) {ArrayList<Score> list = new ArrayList<Score>();Connection conn = C3P0Utils.getConn();PreparedStatement psmt = null;ResultSet rs = null;try {                                               String sql = "select * from tbl_score where subject = ?";psmt = conn.prepareStatement(sql);psmt.setString(1, subject);// 执行rs = psmt.executeQuery();while (rs.next()) {Score score = new Score();score.setId(rs.getInt("id"));score.setSubject(rs.getString("subject"));score.setScore(rs.getInt("score"));score.setSid(rs.getInt("sid"));list.add(score);}  } catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();} finally {C3P0Utils.closeJDBC(conn, psmt, rs);}return list;}public Score getScoreById(int id) {Connection con = null;PreparedStatement psmt = null;ResultSet rs = null;Score score = null;String sql = "select * from tbl_score where id=" + id;try {con = C3P0Utils.getConn();psmt = con.prepareStatement(sql);rs = psmt.executeQuery(sql);while (rs.next()) {int mid = rs.getInt("id");String subject = rs.getString("subject");int mscore = rs.getInt("score");int sid = rs.getInt("sid");// 创建 Score对象score = new Score(mid, subject, mscore, sid);}} catch (Exception e) {e.printStackTrace();} finally {C3P0Utils.closeJDBC(con, psmt, rs);}return score;}public ArrayList<Score> getScoreBySid(int sid) {ArrayList<Score> list = new ArrayList<Score>();Connection con = null;PreparedStatement psmt = null;ResultSet rs = null;Score score = null;String sql = "select * from tbl_score where sid = ?";try {con = C3P0Utils.getConn();psmt = con.prepareStatement(sql);psmt.setInt(1, sid);rs = psmt.executeQuery();while (rs.next()) {int mid = rs.getInt("id");String subject = rs.getString("subject");int mscore = rs.getInt("score");int sdid = rs.getInt("sid");// 创建 Score对象score = new Score(mid, subject, mscore, sdid);list.add(score);}} catch (Exception e) {e.printStackTrace();} finally {C3P0Utils.closeJDBC(con, psmt, rs);}return list;}public ArrayList<Score> getInfoByMoreSid(String msql) {ArrayList<Score> list = new ArrayList<Score>();Connection con = null;PreparedStatement psmt = null;ResultSet rs = null;Score score = null;String sql = "select * from tbl_score where ?";try {con = C3P0Utils.getConn();psmt = con.prepareStatement(sql);psmt.setString(1, msql);rs = psmt.executeQuery();while (rs.next()) {int mid = rs.getInt("id");String subject = rs.getString("subject");int mscore = rs.getInt("score");int sdid = rs.getInt("sid");// 创建 Score对象score = new Score(mid, subject, mscore, sdid);list.add(score);}} catch (Exception e) {e.printStackTrace();} finally {C3P0Utils.closeJDBC(con, psmt, rs);}return list;}
}

StudentDao.java

package com.zz.dao;import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;import com.zz.pojo.Student;
import com.zz.util.C3P0Utils;public class StudentDao {public ArrayList<Student> getStudent() {ArrayList<Student> list = new ArrayList<Student>();Connection con = null;Statement st = null;ResultSet rs = null;String sql = "select * from tbl_student";try {con = C3P0Utils.getConn();st = con.createStatement();rs = st.executeQuery(sql);while (rs.next()) {Student student = new Student();student.setId(rs.getInt("id"));student.setName(rs.getString("name"));student.setPhone(rs.getString("phone"));student.setClassname(rs.getString("classname"));System.out.println("shfisf");list.add(student);}} catch (Exception e) {e.printStackTrace();} finally {C3P0Utils.closeJDBC(con, st, rs);}return list;}public ArrayList<Student> getKindOfClassname() {ArrayList<Student> list = new ArrayList<Student>();Connection con = null;Statement st = null;ResultSet rs = null;String sql = "select distinct classname from tbl_student";try {con = C3P0Utils.getConn();st = con.createStatement();rs = st.executeQuery(sql);while (rs.next()) {Student student = new Student();student.setClassname(rs.getString("classname"));list.add(student);}} catch (Exception e) {e.printStackTrace();} finally {C3P0Utils.closeJDBC(con, st, rs);}return list;}public ArrayList<Student> getInfoByCname(String classname) {ArrayList<Student> list = new ArrayList<Student>();Connection con = null;PreparedStatement st = null;ResultSet rs = null;String sql = "select * from tbl_student where classname=?";try {con = C3P0Utils.getConn();st = con.prepareStatement(sql);st.setString(1, classname);rs = st.executeQuery();while (rs.next()) {Student student = new Student();student.setId(rs.getInt("id"));student.setName(rs.getString("name"));student.setPhone(rs.getString("phone"));student.setClassname(rs.getString("classname"));list.add(student);}} catch (Exception e) {e.printStackTrace();} finally {C3P0Utils.closeJDBC(con, st, rs);}return list;}public ArrayList<Student> getInfoByName(String name) {ArrayList<Student> list = new ArrayList<Student>();Connection conn = C3P0Utils.getConn();PreparedStatement psmt = null;ResultSet rs = null;String sql = "select * from tbl_student where name=?";try {conn = C3P0Utils.getConn();psmt = conn.prepareStatement(sql);psmt.setString(1, name);rs = psmt.executeQuery();while (rs.next()) {Student student = new Student();student.setId(rs.getInt("id"));student.setName(rs.getString("name"));student.setPhone(rs.getString("phone"));student.setClassname(rs.getString("classname"));list.add(student);}} catch (Exception e) {e.printStackTrace();} finally {C3P0Utils.closeJDBC(conn, psmt, rs);}return list;}public int getIdByName(String name) {Connection conn = C3P0Utils.getConn();PreparedStatement psmt = null;ResultSet rs = null;int sid = 0;String sql = "select * from tbl_student where name=?";try {conn = C3P0Utils.getConn();psmt = conn.prepareStatement(sql);psmt.setString(1, name);rs = psmt.executeQuery();while (rs.next()) {sid = rs.getInt("id");return sid;}} catch (Exception e) {e.printStackTrace();} finally {C3P0Utils.closeJDBC(conn, psmt, rs);}return sid;}public int getIdOnNameCName(String name,String classname) {Connection conn = C3P0Utils.getConn();PreparedStatement psmt = null;ResultSet rs = null;int sid = 0;String sql = "select * from tbl_student where name = ? and classname = ?";try {conn = C3P0Utils.getConn();psmt = conn.prepareStatement(sql);psmt.setString(1, name);psmt.setString(2, classname);rs = psmt.executeQuery();while (rs.next()) {sid = rs.getInt("id");return sid;}} catch (Exception e) {e.printStackTrace();} finally {C3P0Utils.closeJDBC(conn, psmt, rs);}return sid;}public Student getStudentById(int id) {Connection con = null;PreparedStatement psmt = null;ResultSet rs = null;Student student = null;String sql = "select * from tbl_student where id=" + id;try {con = C3P0Utils.getConn();psmt = con.prepareStatement(sql);rs = psmt.executeQuery(sql);while (rs.next()) {student = new Student();student.setId(rs.getInt("id"));student.setName(rs.getString("name"));student.setPhone(rs.getString("phone"));student.setClassname(rs.getString("classname"));return student;}} catch (Exception e) {e.printStackTrace();} finally {C3P0Utils.closeJDBC(con, psmt, rs);}return student;}public ArrayList<Student> getInfoListById(int id) {ArrayList<Student> list = new ArrayList<Student>();Connection con = null;PreparedStatement psmt = null;ResultSet rs = null;Student student = null;String sql = "select * from tbl_student where id=" + id;try {con = C3P0Utils.getConn();psmt = con.prepareStatement(sql);rs = psmt.executeQuery(sql);while (rs.next()) {student = new Student();student.setId(rs.getInt("id"));student.setName(rs.getString("name"));student.setPhone(rs.getString("phone"));student.setClassname(rs.getString("classname"));list.add(student);}} catch (Exception e) {e.printStackTrace();} finally {C3P0Utils.closeJDBC(con, psmt, rs);}return list;}
}

com.zz.pojo

Score.java

package com.zz.pojo;import java.io.Serializable;public class Score implements Serializable{private static final long serialVersionUID = 1L;private Integer id;private String subject;private Integer score;private Integer sid;public Score() {super();}public Score(String subject, Integer score, Integer sid) {super();this.subject = subject;this.score = score;this.sid = sid;}public Score(Integer id, String subject, Integer score, Integer sid) {super();this.id = id;this.subject = subject;this.score = score;this.sid = sid;}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getSubject() {return subject;}public void setSubject(String subject) {this.subject = subject;}public Integer getScore() {return score;}public void setScore(Integer score) {this.score = score;}public Integer getSid() {return sid;}public void setSid(Integer sid) {this.sid = sid;}@Overridepublic String toString() {return "Score [id=" + id + ", subject=" + subject + ", score=" + score + ", sid=" + sid + "]";}}

Student.java

package com.zz.pojo;import java.io.Serializable;public class Student implements Serializable{/*** */private static final long serialVersionUID = 1L;private Integer id;private String name;private String phone;private String classname;public Student() {super();}public Student(String name, String phone, String classname) {super();this.name = name;this.phone = phone;this.classname = classname;}public Student(Integer id, String name, String phone, String classname) {super();this.id = id;this.name = name;this.phone = phone;this.classname = classname;}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getPhone() {return phone;}public void setPhone(String phone) {this.phone = phone;}public String getClassname() {return classname;}public void setClassname(String classname) {this.classname = classname;}@Overridepublic String toString() {return "Student [id=" + id + ", name=" + name + ", phone=" + phone + ", classname=" + classname + "]";}}

com.zz.util

C3P0Utils.java

package com.zz.util;import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;import com.mchange.v2.c3p0.ComboPooledDataSource;public class C3P0Utils {static ComboPooledDataSource dataSource = new ComboPooledDataSource("mysql");public static Connection getConn() {try {Connection conn = dataSource.getConnection();return conn;} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return null;}public static void closeJDBC(Connection con,Statement st,ResultSet rs) {if(rs!=null) {try {rs.close();} catch (SQLException e) {e.printStackTrace();}}if(st!=null) {try {st.close();} catch (SQLException e) {e.printStackTrace();}}try {if(con!=null && con.isClosed()==false) {con.close();}} catch (SQLException e) {e.printStackTrace();}}
}

src

c3p0-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config><!--默认配置 --><default-config><property name="initialPoolSize">10</property><property name="maxIdleTime">30</property><property name="maxPoolSize">100</property><property name="minPoolSize">10</property><property name="maxStatements">200</property></default-config><!--配置连接池mysql --><named-config name="mysql"><property name="driverClass">com.mysql.jdbc.Driver</property><property name="jdbcUrl">jdbc:mysql://localhost:3306/test</property><property name="user">root</property><property name="password">123456</property><property name="initialPoolSize">10</property><property name="maxIdleTime">30</property><property name="maxPoolSize">100</property><property name="minPoolSize">10</property><property name="maxStatements">200</property></named-config>
</c3p0-config>

config.properties

#test
show-test.action=com.zz.action.test.Test#info
student-info.action=com.zz.action.student.StudentInfoAction#query
query-bysubject.action=com.zz.action.student.QueryInfoAction#queryB
query-info.action=com.zz.action.student.QueryStudentInfoAction

db

tbl_score.sql

/*
MySQL Data Transfer
Source Host: localhost
Source Database: test
Target Host: localhost
Target Database: test
Date: 2019/10/13 19:38:22
*/SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for tbl_score
-- ----------------------------
DROP TABLE IF EXISTS `tbl_score`;
CREATE TABLE `tbl_score` (`id` int(11) NOT NULL AUTO_INCREMENT,`subject` varchar(20) DEFAULT NULL,`score` int(11) DEFAULT NULL,`sid` int(11) DEFAULT NULL,PRIMARY KEY (`id`),KEY `FK_sid` (`sid`),CONSTRAINT `FK_sid` FOREIGN KEY (`sid`) REFERENCES `tbl_student` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8;-- ----------------------------
-- Table structure for tbl_student
-- ----------------------------
DROP TABLE IF EXISTS `tbl_student`;
CREATE TABLE `tbl_student` (`id` int(11) NOT NULL AUTO_INCREMENT,`name` varchar(20) DEFAULT NULL,`phone` varchar(20) DEFAULT NULL,`classname` varchar(20) DEFAULT NULL,PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;-- ----------------------------
-- Records
-- ----------------------------
INSERT INTO `tbl_score` VALUES ('1', 'Java基础', '80', '1');
INSERT INTO `tbl_score` VALUES ('2', 'Java基础', '60', '2');
INSERT INTO `tbl_score` VALUES ('3', 'Java基础', '90', '3');
INSERT INTO `tbl_score` VALUES ('4', 'Java基础', '70', '4');
INSERT INTO `tbl_score` VALUES ('5', 'Java基础', '80', '5');
INSERT INTO `tbl_score` VALUES ('6', 'Oracle', '80', '1');
INSERT INTO `tbl_score` VALUES ('7', 'Oracle', '90', '2');
INSERT INTO `tbl_score` VALUES ('8', 'Oracle', '70', '3');
INSERT INTO `tbl_score` VALUES ('9', 'Oracle', '80', '4');
INSERT INTO `tbl_score` VALUES ('10', 'Oracle', '76', '5');
INSERT INTO `tbl_score` VALUES ('11', 'Spring', '50', '1');
INSERT INTO `tbl_score` VALUES ('12', 'Spring', '60', '2');
INSERT INTO `tbl_score` VALUES ('13', 'Spring', '60', '3');
INSERT INTO `tbl_score` VALUES ('14', 'Spring', '70', '4');
INSERT INTO `tbl_score` VALUES ('15', 'Spring', '80', '5');
INSERT INTO `tbl_student` VALUES ('1', 'Tom', '123456789', 'STA01');
INSERT INTO `tbl_student` VALUES ('2', 'Mary', '987654321', 'STA01');
INSERT INTO `tbl_student` VALUES ('3', 'Sam', '123456789', 'STA02');
INSERT INTO `tbl_student` VALUES ('4', 'Bill', '123456789', 'STA02');
INSERT INTO `tbl_student` VALUES ('5', 'Mary', '123456789', 'STA02');

lib

c3p0-0.9.1.2.jar
jstl.jar
mysql-connector-java-5.1.6-bin.jar
standard.jar

WEB-INF

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"><display-name>StudentInfo</display-name><welcome-file-list><welcome-file>index.html</welcome-file><welcome-file>index.htm</welcome-file><welcome-file>index.jsp</welcome-file><welcome-file>default.html</welcome-file><welcome-file>default.htm</welcome-file><welcome-file>default.jsp</welcome-file></welcome-file-list><servlet><description></description><display-name>ActionServlet</display-name><servlet-name>ActionServlet</servlet-name><servlet-class>com.zz.controller.ActionServlet</servlet-class></servlet><servlet-mapping><servlet-name>ActionServlet</servlet-name><url-pattern>*.action</url-pattern></servlet-mapping>
</web-app>

WebContent

NewFile.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="student-info.action">点击1</a>
<br/></body>
</html>

studentInfo.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>学生信息展示</title>
<style type="text/css">
body {text-align: center; font-size: 13px;} table {border-collapse: collapse;border:1px solid black;align:center;padding:0px;width:550px;margin: auto;}table, td, th {border: 1px solid black;}
</style>
</head>
<body>
<form action="query-info.action">
<label>科目:</label><input name="subject"/>
<label>姓名:</label><input name="name"/>
<label>班级:</label>
<select id="classname" name="classname" autofocus >
<option value="所有班级">所有班级</option><c:forEach items="${slist }" var="slist"><option value="${slist.classname }">${slist.classname }</option></c:forEach></select>
<button class="submit" type="submit" name="query" value="true" tabindex="80">查询</button>
</form><table><tr><td>编号</td><td>姓名</td><td>班级</td><td>科目</td><td>分数</td></tr><c:forEach items="${ list}" var="list"><tr><td><c:out value="${list.id }"></c:out></td><td>${map[list.sid ].name}</td><td>${map[list.sid ].classname}</td><td><c:out value="${list.subject }"></c:out></td><td><c:out value="${list.score }"></c:out></td></tr></c:forEach></table>
</body>
</html>

效果图

运行NewFile.jsp

查询数据后展示

根据科目查询例如:Oracle

根据姓名查询例如:Tom

根据班级查询例如:STA01

根据科目和姓名查询例如:STA01

还有其他条件组合查询

javaWeb学生信息查询相关推荐

  1. Javaweb学生信息管理系统(Mysql+JSP+MVC+CSS)

    项目源码及数据库: 链接:https://pan.baidu.com/s/1ktUyxbOI9lljWr-HRTRIiQ?pwd=1024 提取码:1024 目录 一.项目介绍 二.运行效果 1.登录 ...

  2. java写的学生信息查询系统_Java编写学生信息查询系统,报错!!!

    在窗口ClientFrame中有一个窗格,Newstudentinfo和Selectstudentinfo独立运行都没问题,但是在ClientFrame中只运行Selectstudentinfo,录入 ...

  3. 基于51单片机学生信息查询与显示

    设计内容 用51单片机.点阵式LED(或1602屏).4×4键盘以及串行接口组成学生信息的显示与查询系统设计.基本要求是在键盘输入学生姓名后,点阵LED屏能够滚动显示学生相关信息,至少两位同学信息,例 ...

  4. Mr.张小白(案例:学生信息查询系统的MyBatis的实现)

    学生信息查询系统 一.步骤 1.引入相关依赖pom.xml <?xml version="1.0" encoding="UTF-8"?> <p ...

  5. 【大学生软件测试基础】历年学生信息查询界面 - 正交表

    某系统"历年学生信息查询"的功能界面如下图所示,利用正交实验法对其设计测试用例. 任务1:根据上面的需求找出因子与水平: 任务2:根据因子与水平数,选择合适的正交表: 任务3: 根 ...

  6. JavaWeb学生信息管理系统_查询V1.0

    项目简介 1)在MySQL数据库中创建一个StudentGradeTable数据表,添加字段FlowId,Type,IdCard,ExamCard,StudentName,Location,Grade ...

  7. javaweb项目实现学生信息查询

    一.开发环境配置 1.1 JDK环境 1.1.1 jdk下载 进入oracle官网 oracle 点击Resources 点击Downloads --> JDK 点击Java archive,并 ...

  8. 【Java】StudentsInfoQuery(简单的学生信息查询系统)

    周末作业,写的草草,BUG很多,直接贴代码. 基于文本文档的,不是数据库. 功能极其有限,也没有用WindowBuilder. 教师查询窗口 package wh.one;import java.aw ...

  9. javaweb旅游信息查询系统

    通过对用户需求的分析,我们可以分析出该旅游信息查询系统大致可以分为:用户端和管理员端.用户端分为普通游客和两种.普通游客的主要功能包括出发地查询.目的地查询.线路查询.旅行社查询.租车信息查询.导游信 ...

最新文章

  1. CEGUI Lua 编码
  2. linux mysql 升级_linux升级mysql
  3. About Instruments
  4. NOLOGGINGFORCE LOGGING
  5. springboot工具类
  6. findler mac 隐藏文件_Fiddler配合Proxifier抓包PC客户端HTTPS明文数据
  7. loj#2340. 「WC2018」州区划分
  8. Python——匿名函数lambda
  9. php-resque 轻量级队列
  10. 【渝粤教育】电大中专跨境电子商务理论与实务 (3)作业 题库
  11. 算法的定义、特征及其算法设计的要求
  12. uploader.php,使用uploader上传拍摄的图片php后端代码出错~求助~
  13. 百度网盘加速下载方法——系统自带的提速模式和积分模式区别
  14. 数论--P8845 [传智杯 #4 初赛] 小卡和质数
  15. 两台电脑用网线直连传文件
  16. 虚拟机云服务器6.0教程pdf,虚拟机云服务器6.0教程pdf
  17. 【BugKu-CTF论坛writeup(杂项)】图穷匕见
  18. 汉字的Unicode 内码
  19. 针对前端js加密解密方法的兼容问题(兼容ie5以上哦)
  20. 大学期间所有课设及大作业源代码

热门文章

  1. 使用 pip 安装serial 串口通讯模块
  2. ArtistV1——艺术家V1[STM32F1 | 写字机 | GRBL | LVGL | WIFI]
  3. 计数器代码php,计数器代码_php计数器的简单代码举例
  4. 谷歌翻译退出中国,不妨试试这 6 款免费好用的翻译工具!
  5. GNN图神经网络详述-01
  6. 区块链创新论坛成“京交会”新亮点:思源推出创新区块链解决方案
  7. 美国计算机语言学比较好的大学,美国哪所大学数据分析专业最好?
  8. 关于 Kubernetes中Volume实操的一些笔记
  9. 七十天极限学习挑战[2019/7.7-9.15]
  10. 基本全局阈值法(basic global thresholding)MATLAB实现