Ejemplo n.º 1
0
  @Override
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // 参数传入
    response.setContentType("text/html;charset=utf-8");
    PrintWriter out = response.getWriter();
    request.setCharacterEncoding("utf-8");
    String type = request.getParameter("type");
    // 通过type判断 为go 更新试题卷面
    if (type.equals("go")) {
      session = HibernateSessionFactory.getSession();
      ts = session.beginTransaction();
      // 获取所有的试题题目
      list = queDao.findAll();
      // 循环试题题目,获取所有的试题明细
      for (int i = 0; i < list.size(); i++) {
        que = (Que) list.get(i);
        listEntry = queDao.findEntryByQue(que);
        queEntrys.clear();
        for (int j = 0; j < listEntry.size(); j++) {
          queEntry = (Queentry) listEntry.get(j);

          queEntrys.add(queEntry);
        }
        // 将试题题目和明细,逐个传入网页
        response.getWriter().write(getStr(que, queEntrys, i));
      }

      ts.commit();
      session.close();
    } else if (type.equals("answer")) {
      // 提交答案,判断是否正确并反馈
      strAnswer = request.getParameter("answer");
      response.getWriter().write(checkAnwer(strAnswer));
    }
  }
Ejemplo n.º 2
0
  private String checkAnwer(String strAn) {
    // TODO Auto-generated method stub
    a = strAn.split(";");
    // 拼接XML 3列
    doc = DocumentHelper.createDocument();
    root = doc.addElement("table");
    root.addAttribute("data-role", "table");
    root.addAttribute("data-mode", "columntoggle");
    root.addAttribute("class", "ui-responsive table-stripe");
    ele = root.addElement("thead");
    ele = ele.addElement("tr");
    ele.addAttribute("class", "ui-bar-c");
    // 列标题
    ele.addElement("th").setText("题目");
    eleH1 = ele.addElement("th");
    eleH1.setText("选择");
    eleH1.setAttributeValue("data-priority", "1");
    eleH1 = ele.addElement("th");
    eleH1.setText("正确答案");
    eleH1.setAttributeValue("data-priority", "1");
    ele = root.addElement("tbody");
    // 增加信息行
    for (String strA : a) {
      aS = strA.split("\\|"); // 注意 “|”的转义
      ele = ele.addElement("tr");
      que = queDao.findBystrId(aS[0]); // 题目
      queEntry = queEntryDao.findBystrId(aS[1]); // 选择
      // 判断回答是否正确
      // if (queEntry.getId().equals(que.getAnswer())) {
      ele.addElement("td").setText(que.getQueDesc());
      ele.addElement("td").setText(queEntry.getDesc());
      ele.addElement("td").setText(queEntryDao.findBystrId(que.getAnswer()).getDesc());
      // } else {
      // System.out.println("error");
      // }

    }
    return doc.getRootElement().asXML();
  }