示例#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));
    }
  }
示例#2
0
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    System.out.println("EditPerson!!!!!!!!!!!!!!!!!");

    String Way = request.getParameter("act");
    System.out.println(Way);
    String ID = request.getParameter("id");
    String Name = request.getParameter("name");
    String Sex = request.getParameter("sex");
    String Birthday = request.getParameter("birthday");
    String Nation = request.getParameter("nation");
    // String Mail = request.getParameter("mail");
    String Address = request.getParameter("address");
    String Phone = request.getParameter("phone");

    //		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    //		String datetime = formatter.format(new java.util.Date());

    StudentinfoDAO MyStudentDAO = new StudentinfoDAO();
    Studentinfo MyStudentInfo;

    Session s = (Session) HibernateSessionFactory.getSession();
    if (Way.equalsIgnoreCase("edit")) {
      System.out.println("编辑!");
      MyStudentInfo = MyStudentDAO.findById(ID);
      MyStudentInfo.setName(Name);
      MyStudentInfo.setSex(Sex);
      MyStudentInfo.setNation(Nation);
      MyStudentInfo.setEmail("");
      MyStudentInfo.setAddress(Address);

      /*	String TempString[]=Birthday.split("年");
      int Year=Integer.parseInt(TempString[0]);
      System.out.println(Year);

      String TempString1[]=TempString[1].split("月");
      int Month=Integer.parseInt(TempString1[0]);
      System.out.println(Month);
      String TempString2[]=TempString1[1].split("日");
      int Day=Integer.parseInt(TempString2[0]);

      System.out.println(Day);

      */
      DateFormat formater = new SimpleDateFormat("yyyy年MM月dd日");
      Date d = null;
      Date MyDate = null;

      try {
        d = formater.parse(Birthday);
      } catch (ParseException e) {

      } finally {
        MyDate = d;
      }

      // System.out.println(MyDate.getYear());
      MyStudentInfo.setBirthday(MyDate);
      MyStudentInfo.setPhoneNumber(Phone);
      System.out.println(Name);
      System.out.println(Sex);

      MyStudentDAO.save(MyStudentInfo);
    } else if (Way.equalsIgnoreCase("add")) {
      System.out.println("添加!");
      MyStudentInfo = new Studentinfo();
      MyStudentInfo.setSId(ID);
      MyStudentInfo.setPassword("1234");
      MyStudentInfo.setPinCode("1234");
      MyStudentInfo.setName(Name);
      MyStudentInfo.setSex(Sex);
      MyStudentInfo.setNation(Nation);
      MyStudentInfo.setEmail("");
      MyStudentInfo.setAddress(Address);

      DateFormat formater = new SimpleDateFormat("yyyy年MM月dd日");
      Date d = null;
      Date MyDate = null;

      try {
        d = formater.parse(Birthday);
      } catch (ParseException e) {

      } finally {
        MyDate = d;
      }

      MyStudentInfo.setBirthday(MyDate);
      MyStudentInfo.setPhoneNumber(Phone);
      System.out.println(Name);
      System.out.println(Sex);

      MyStudentDAO.save(MyStudentInfo);

      ServletContext sc = request.getSession().getServletContext();
      String filePath = "";

      filePath = sc.getRealPath("/") + "file/" + ID + "/";

      File file = new File(filePath);
      file.mkdirs();

    } else if (Way.equalsIgnoreCase("delete")) {
      MyStudentInfo = MyStudentDAO.findById(ID);
      StudentCourseDAO MyStudentCourseDAO = new StudentCourseDAO();

      List<StudentCourse> StudentCourseList = MyStudentCourseDAO.findBySId(ID);
      for (int i = 0; i < StudentCourseList.size(); i++) {
        StudentCourse temp = (StudentCourse) StudentCourseList.get(i);
        MyStudentCourseDAO.delete(temp);
      }

      MyStudentDAO.delete(MyStudentInfo);
    }

    try {
      Transaction ts = s.beginTransaction();
      ts.commit();
    } catch (Exception e) {

    } finally {
      s.close();
      List<Studentinfo> StudentList = MyStudentDAO.findAll();

      request.setAttribute("pageNumber", 1);
      request.setAttribute("Jump", 2);
      HttpSession hs = request.getSession();

      if (!Way.equalsIgnoreCase("delete")) {
        hs.setAttribute("StudentID", ID);
        MyStudentInfo = MyStudentDAO.findById(ID);
        hs.setAttribute("StudentName", MyStudentInfo.getName());
        hs.setAttribute("Sex", MyStudentInfo.getSex());

        Date TempDate = MyStudentInfo.getBirthday();
        String TempString;
        DateFormat formater = new SimpleDateFormat("yyyy年MM月dd日");
        TempString = formater.format(TempDate);
        hs.setAttribute("StudentBirthday", TempString);
        hs.setAttribute("StudentNation", MyStudentInfo.getNation());
        hs.setAttribute("StudentAddress", MyStudentInfo.getAddress());
        hs.setAttribute("StudentEmail", MyStudentInfo.getEmail());
        hs.setAttribute("StudentPhone", MyStudentInfo.getPhoneNumber());
      }

      hs.setAttribute("MyStudentList", StudentList);

      request.getRequestDispatcher("admin.jsp").forward(request, response);
    }
  }