接小项目,课程设计、毕业设计、微信小程序、web应用都可以(本人互联网大厂软件开发工程师),有需要联系qq:3524227028
用JSP、Servlet、JavaBean、JDBC技术实现在线测试系统
要求如下:
使用JSP+Servlet+JavaBean的MVC模式开发一个简单的在线测试系统。
基本功能:学生注册、登录后可进行答题和提交试卷。老师可以进行学生管理和成绩查询(成绩由系统自动打分)。
- 学生管理:主要有编辑、删除功能。
- 成绩查询:主要有成绩排序、按姓名查询、按成绩区间查询功能。
数据库表基本要求:字段长度自拟。
student表(学号(主键),姓名,密码)
score表(学号,成绩) ----注意:为减少冗余,此表不包含学生姓名字段
下面是本人的实现效果图:
首页登录:
学生身份登录
答题测试
管理员(老师)身份登录
学生管理
成绩查询
按分数区间查询(本图片为10-30分)
按姓名查询(本例为zz)
功能说明:
1.在未登陆的情况下,不能通过地址栏直接访问后台管理员的操作控制器,强行访问直接跳转到登录界面。
2.学生具有登录注册功能,id为唯一标识,可同名。可多次答题,提交试卷后直接退出。
3.管理员老师端可以对学生信息进行修改,但是id不能改,每次修改都会同步到数据库。删除学生时,会将成绩表里的记录相应删除。
4.升序降序都已实现,升序降序都以分数大小为主,若分数相同,则比较id。
由于代码过多,下面就贴出部分代码,全部代码本人已经上传到github上,下面是链接:
https://github.com/jiang-congcong/JavaEE_MVC__testonline
Find.java
package servlets;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import beans.User;
import dao.UserDAO;
/**
* Servlet implementation class Find
*/
public class Find extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Find() {
super();
// TODO Auto-generated constructor stub
}
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session=request.getSession();
User u1 = (User)session.getAttribute("user");
PrintWriter out = response.getWriter();
String flag =(String) session.getAttribute("flag");
//boolean
//session.setAttribute("user_list", new UserDAO().getAllUsers());
//response.sendRedirect("admin.jsp");
if(u1!=null||flag!=null) {
String s1 = request.getParameter("sco1");
String s2 = request.getParameter("sco2");
String name = request.getParameter("name");
if(name.length()>0) {
session.setAttribute("score_list", new UserDAO().getUserByUsername(name));
//response.sendRedirect("http://localhost:8080/MVC/scorelist.jsp");
response.sendRedirect("Scorelist");
}
else if(s1.length()>0&&s2.length()>0) {
int sc1 = Integer.parseInt(request.getParameter("sco1"));
int sc2 = Integer.parseInt(request.getParameter("sco2"));
session.setAttribute("score_list", new UserDAO().getUserByScore(sc1, sc2));
//response.sendRedirect("http://localhost:8080/MVC/scorelist.jsp");
response.sendRedirect("Scorelist");
}
else {
session.setAttribute("score_list", new UserDAO().getAllUsers());
//response.sendRedirect("http://localhost:8080/MVC/scorelist.jsp");
response.sendRedirect("Scorelist");
}
}
else {
//out.print("Find.java");
response.sendRedirect("login1.jsp");
}
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//response.getWriter().append("Served at: ").append(request.getContextPath());
service(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
Scorelist.java
package servlets;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import beans.User;
import beans.Userscore;
/**
* Servlet implementation class Scorelist
*/
public class Scorelist extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
protected int upsort(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
int id=0;
String username1 = null;
int score1=0;
//ServletContext application = getServletContext();
HttpSession session=request.getSession();
List<Userscore> score_list = (List<Userscore>) session.getAttribute("score_list");
Comparator_score comparator=new Comparator_score();
Collections.sort(score_list, comparator);
out.print("<h2>成绩榜</h2>");
if(score_list==null){
out.print("<h3>没有成绩</h3>");
}
else{
out.print("\n");
out.print("<table border=\"1\">\r\n" +
" <tr>\r\n" +
" <th>学号</th> <th>用户名</th> <th colspan=\"2\"> 成绩 </th>\r\n" +
" </tr>");
if (score_list != null) {
for (Userscore u : score_list) {
out.print("<tr>");
out.print("<td>"+u.getId()+"</td>");
out.print("<td>"+u.getUsername()+"</td>");
out.print("<td>"+u.getScore()+"</td>");
out.print("</tr>");
}
}
}
return 0;
}
public Scorelist() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//response.getWriter().append("Served at: ").append(request.getContextPath());
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
int id=0;
String username1 = null;
int score1=0;
//ServletContext application = getServletContext();
HttpSession session=request.getSession();
User u2 = (User)session.getAttribute("user");
String flag =(String) session.getAttribute("flag");
if(u2!=null||flag!=null) {
List<Userscore> score_list = (List<Userscore>) session.getAttribute("score_list");
out.print("<h2>成绩榜</h2>");
if(score_list==null){
out.print("<h3>没有成绩</h3>");
}
else{
out.print("\n");
out.print("<table border=\"1\">\r\n" +
" <tr>\r\n" +
" <th>学号</th> <th>用户名</th> <th colspan=\"2\"> 成绩 </th>\r\n" +
" </tr>");
if (score_list != null) {
for (Userscore u : score_list) {
out.print("<tr>");
out.print("<td>"+u.getId()+"</td>");
out.print("<td>"+u.getUsername()+"</td>");
out.print("<td>"+u.getScore()+"</td>");
out.print("</tr>");
}
}
}
out.print("<button type='button'"+ "οnclick="+"window.location.href='scorelist_up'"+">"+"升序"+"</button>"+" ");
out.print("<button type='button'"+ "οnclick="+"window.location.href='scorelist_down'"+">"+"降序"+"</button>");
out.print(" "+"<button type='button'"+ "οnclick="+"window.location.href='Logout'"+">"+"退出"+"</button>");
out.print("\n");
}
else {
//out.print("Scorelist");
response.sendRedirect("login1.jsp");
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}