首页 新闻 会员 周边 捐助

请用所给代码搭建一个MVC结构的选择题答题模块

0
[待解决问题]

本人新手菜鸟,完全摸不着头脑,题目代码如下,请大神指点一下!谢谢各位!

要求如下:
(1)在页面上能够显示所有的题目列表的基本信息;
(2)能够显示当前题目、题目选项;
(3)能够通过JavaScript判断答案的正确性;
(4)学生能够通过上一题、下一题来进行题目选择。

  1// JSP页面代码如下:
  2 
  3 <%@ page language="java" contentType="text/html; charset=utf-8"
  4 pageEncoding="utf-8"%>
  5 <%@ page import="java.util.*" %>
  6 <%@ page import="studentlab.mvc.*" %>
  7 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  8 <html>
  9 <head>
 10 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 11 <title>Insert title here</title>
 12 </head>
 13 <body>
 14 <%
 15 List<Question> list = (List<Question>)request.getAttribute("list");
 16 Question q = (Question)request.getAttribute("question");
 17 %>
 18 <a href="exam?id=<%=q.getId()-1%>">上一题</a> <a href="exam?id=<%=q.getId()+1%>">">下一题</a>
 19 </body>
 20 <div>第<%=q.getId()%>题 <%=q.getDescription()%></div>
 21 
 22 </html>
 23 
 24 //ExamServlet代码如下
 25 
 26 package studentlab.mvc;
 27 
 28 import java.io.IOException;
 29 import javax.servlet.ServletException;
 30 import javax.servlet.annotation.WebServlet;
 31 import javax.servlet.http.HttpServlet;
 32 import javax.servlet.http.HttpServletRequest;
 33 import javax.servlet.http.HttpServletResponse;
 34 
 35 /**
 36 * Servlet implementation class ExamServlet
 37 */
 38 @WebServlet("/exam")
 39 public class ExamServlet extends HttpServlet {
 40 private static final long serialVersionUID = 1L;
 41 
 42 /**
 43 * @see HttpServlet#HttpServlet()
 44 */
 45 public ExamServlet() {
 46 super();
 47 // TODO Auto-generated constructor stub
 48 }
 49 
 50 /**
 51 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 52 */
 53 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 54 
 55 }
 56 
 57 /**
 58 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 59 */
 60 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 61 doGet(request, response);
 62 }
 63 
 64 }
 65 
 66  
 67 
 68 //Question代码如下
 69 
 70 package studentlab.mvc;
 71 
 72 public class Question {
 73 private int id;
 74 private String description;
 75 private String options;
 76 private String answer;
 77 
 78 public int getId() {
 79 return id;
 80 }
 81 public void setId(int id) {
 82 this.id = id;
 83 }
 84 public String getDescription() {
 85 return description;
 86 }
 87 public void setDescription(String description) {
 88 this.description = description;
 89 }
 90 public String getOptions() {
 91 return options;
 92 }
 93 public void setOptions(String options) {
 94 this.options = options;
 95 }
 96 public String getAnswer() {
 97 return answer;
 98 }
 99 public void setAnswer(String answer) {
100 this.answer = answer;
101 }
102 
103 }
104 
105// QuestionDao代码如下:
106 
107  
108 
109 package studentlab.mvc;
110 
111 import java.sql.*;
112 import java.util.*;
113 //import java.util.List;
114 
115 public class QuestionDao {
116 public List<Question> queryAll(){
117 List<Question> list =new ArrayList<Question>();
118 String url="jdbc:h2:D:/temp/h2/mydb";
119 try {
120 Class.forName("org.h2.Driver");
121 Connection conn = DriverManager.getConnection(url,"sa",""); 
122 Statement stmt = conn.createStatement();
123 String sql="select * from exam";
124 ResultSet rs = stmt.executeQuery(sql);
125 while(rs.next()){
126 Question q = new Question();
127 q.setId(rs.getInt(1));
128 q.setDescription(rs.getString(2));
129 q.setOptions(rs.getString(3));
130 q.setAnswer(rs.getString(3));
131 list.add(q);
132 }
133 rs.close();
134 stmt.close();
135 conn.close();
136 } catch (ClassNotFoundException e) {
137 // TODO Auto-generated catch block
138 e.printStackTrace();
139 } catch (SQLException e) {
140 // TODO Auto-generated catch block
141 e.printStackTrace();
142 } 
143 
144 return list;
145 }
146 
147 public Question queryById(int id){
148 Question q = null;
149 
150 return q;
151 
152 } 
153 
154 }

 

大狗比爱吃葱的主页 大狗比爱吃葱 | 菜鸟二级 | 园豆:202
提问于:2016-12-26 17:44
< >
分享
所有回答(2)
0

代码也不贴代码块里,让人怎么看!

、熙和 | 园豆:1508 (小虾三级) | 2016-12-27 10:08

抱歉啊 不知道这个功能TT

支持(0) 反对(0) 大狗比爱吃葱 | 园豆:202 (菜鸟二级) | 2016-12-27 10:12

@大狗比爱吃葱: 

看了一下, 说的挺明白了, 不知道你哪里不清楚?

1.获取所有题目列表, 进行页面展示(获取数据, 页面可以用el表达式+ c标签, 或者 用小脚本嵌套html代码)

2.获取某一题目, 展示相关选项(根据题目id获取题目, 然后页面展示数据)

3.选择选项后, 用js判断是否与答案匹配. 

4. 同 2,

支持(1) 反对(0) 、熙和 | 园豆:1508 (小虾三级) | 2016-12-27 13:20

@、熙和: 这个获取题目进行展示什么写?他的dopost,doget返回的是什么呢?

支持(0) 反对(0) 大狗比爱吃葱 | 园豆:202 (菜鸟二级) | 2016-12-27 13:58

@大狗比爱吃葱: 

根据请求传过来的题目id, 查询到题目的详情信息, 然后放到request作用域里, 可以返回页面, 在页面上从request把数据显示出来.

或者页面使用ajax请求, servlet  get/post返回题目详情的json格式数据.

 

 

要是不理解, 你去找JSP的资料好好看看

支持(0) 反对(0) 、熙和 | 园豆:1508 (小虾三级) | 2016-12-27 15:44
0

我正在开发这个项目,有问题找我1206284818

silianpan | 园豆:571 (小虾三级) | 2016-12-27 12:16
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册