コード例 #1
0
  public String execute() {
    HttpServletRequest request = ServletActionContext.getRequest();
    HttpSession session = request.getSession();
    User user = (User) session.getAttribute("user");
    int userid = user.getId();
    List<Word> wordList = new ArrayList<Word>();
    if (request.getParameter("getCollect") != null) {
      wordList = userCollectLibService.getUserCollectLibByUid(userid);
      String showstr1 = "四级: ";
      String showstr2 = "六级: ";
      String showstr3 = "要你命3000: ";
      String showstr4 = "TOEFL: ";
      Word word = null;
      // String lib_name = "";
      // Set<String> lib = new HashSet<String>();
      for (int i = 0; i < wordList.size(); i++) {
        word = wordList.get(i);
        // lib_name = wordLibService.getLibNameByLibid(word.getLib_id());
        // lib.add(lib_name);
        if (word.getLib_id() == 1) {
          showstr1 += word.getWord() + "   ";
        } else if (word.getLib_id() == 3) {
          showstr2 += word.getWord() + "   ";
        } else if (word.getLib_id() == 6) {
          showstr3 += word.getWord() + "   ";
        } else if (word.getLib_id() == 10) {
          showstr4 += word.getWord() + "   ";
        }
      }
      request.setAttribute("message", showstr1);
      request.setAttribute("message2", showstr2);
      request.setAttribute("message3", showstr3);
      request.setAttribute("message4", showstr4);
      return IConstants.GET_COLLECTION;
    } else {
      String submitName = "";
      if (request.getParameter("0") == null) {
        if (request.getParameter("1") == null) {
          if (request.getParameter("2") == null) {
            if (request.getParameter("3") != null) {
              submitName = "3";
            }
          } else submitName = "2";
        } else submitName = "1";
      } else submitName = "0";
      String wid = request.getParameter("wid" + submitName).toString();
      String uid = request.getParameter("uid").toString();
      try {
        if (!userCollectLibService.isWordInUserCollectLib(Integer.parseInt(wid))) {
          userCollectLibService.AddwordToUserCollectLib(
              Integer.parseInt(wid), Integer.parseInt(uid));
          request.setAttribute("message", uid + "添加" + wid + "成功!");
          return IConstants.ADD_SUCCESS;
        } else {
          request.setAttribute("message", wid + "已存在于您的单词库");

          return IConstants.ALREADY_EXIST;
        }

      } catch (Exception e) {
        request.setAttribute("message", "登陆失败");
        return IConstants.SESSION_EXPIRED;
      }
    }
  }
コード例 #2
0
  @Override
  public String execute() throws Exception {

    HttpServletRequest request = ServletActionContext.getRequest();
    HttpSession session = request.getSession();
    User user = (User) session.getAttribute("user");
    int uid = user.getId();
    int currentlibID = user.getCurrentLib();
    // String nowLibName = wordLibService.getLibNameByLibid(currentlibID);
    List<Wordlib> wordlib = new ArrayList<Wordlib>();
    wordlib = wordLibService.getAllWordLib();

    Wordlib Lib = null;
    String libname = "";
    int libId = 0;
    String description = "";
    String imgSrc = "";
    String inputcolor = "";
    String inputvalue = "";
    String disable = "";
    int inputname = -1;
    int wordCount = 0;
    String longSTR = "";
    for (int i = 0; i < wordlib.size(); i++) {
      Lib = wordlib.get(i);
      libId = Lib.getId();
      libname = wordLibService.getLibNameByLibid(libId);
      description = Lib.getDescription();
      wordCount = wordLibService.getLibCountById(libId);
      imgSrc = "images/gre_3k.jpg";

      if (libId == currentlibID) {
        inputcolor = "style=\"background:#e77e23;\"";
        inputvalue = "Using";
        disable = " disabled=\"true\"";
      } else {
        inputcolor = "";
        inputvalue = "Switch";
        disable = "";
      }
      inputname = libId;
      longSTR +=
          "<div><div><img src=\""
              + imgSrc
              + "\"></div><div><h3>"
              + libname
              + "</h3><p>"
              + description
              + "</p>Total: <span>"
              + wordCount
              + "</span><br></br><input "
              + inputcolor
              + "type=\"submit\" value=\""
              + inputvalue
              + "\""
              + disable
              + "\" name=\"lib"
              + inputname
              + "\"/></div></div>";
    }
    request.setAttribute("longSTR", longSTR);
    return "ToChooseWordLib";

    //			<div>
    //            <div>
    //                <img src="images/gre_3k.jpg">
    //            </div>
    //            <div>
    //                <h3>GRE 3000</h3>
    //                <p>A really good book for GRE test taker</p>
    //                Total: <span>2957</span><br></br>
    //                <input style="background:#e77e23;" type="submit" value="Using" disabled="true"
    // name="${nihao}"/>
    //            </div>
    //        </div>

  }