Package net.sf.json

Examples of net.sf.json.JSONObject


  /**
   * 校验email是否占用
   * @return
   */
  public String validateEmail(){
    JSONObject result=CommonDAO.getSingle(SqlMgr.getSql("CHECK_USER_EMAIL"), email);
    if(result!=null){
      this.outJsonString("false");
    }else{
      this.outJsonString("true");
    }
View Full Code Here


    if(StringUtil.isEmpty(userName)||StringUtil.isEmpty(validateCode)){
      return "failure";
    }
   
    //激活
    JSONObject result=CommonDAO.getSingle(SqlMgr.getSql("CHECK_USER_ID"), userName);
    JSONObject tempCode=result.getJSONObject("vcode");
    String temp=tempCode.toString();
    if(validateCode.equals(temp)){
      CommonDAO.update(SqlMgr.getSql("UPDATE_USER_STATE"),0,userName);
      this.setReqAttr("regMsg", "validateSuccess");
      CommonDAO.update(SqlMgr.getSql("DEL_VCODE"),userName);
    }else{
View Full Code Here

   * 登录
   * @return
   */
  public String login(){
    //校验用户名和密码
    JSONObject result=CommonDAO.getSingle(SqlMgr.getSql("LOGIN_CHECK"), userName,password);
    if(result==null){
      this.setReqAttr("errorMsg", "登录失败,用户名或密码不正确。");
      return "error";
    }else if(result.getString("state").equals("-1")){//已注册,但尚未激活
      this.setReqAttr("regMsg", "EMAIL_NOT_CHECK");
      email=result.getString("email");
      String mailAddr="mail."+email.substring(email.lastIndexOf("@")+1);
      this.setReqAttr("mailAddr",mailAddr);
      return "checkEmail";
    }else if(result!=null){
      //更新用户状态为已登录,并更新IP地址、记录最后登录时间
      String ipAddr=this.getIpAddr();
      CommonDAO.update(SqlMgr.getSql("USER_LOGIN"),ipAddr,userName);
      //加载用户的权限代码
      JSONArray permissions=CommonDAO.getList(SqlMgr.getSql("GET_USER_PERMISSION"),userName);
      if(permissions!=null){
        Iterator<JSONObject> iter=permissions.iterator();
        while(iter.hasNext()){
          JSONObject jsonObj=iter.next();
          this.setSessionAttr(jsonObj.getString("permission_code"), jsonObj.getString("permission_desc"));
        }
      }
      //取用户资料
      JSONObject userInfo=CommonDAO.getSingle(SqlMgr.getSql("GET_USER_INFO"), userName);
      if(userInfo!=null){
        this.setSessionAttr("nickName",userInfo.get("nick_name"));
        this.setSessionAttr("gradeName",userInfo.get("grade_name"));
        this.setSessionAttr("gender",userInfo.get("gender").equals("0")?"男":"女");
        this.setSessionAttr("cityId",userInfo.get("city_id"));
        this.setSessionAttr("articles",userInfo.get("articles"));
        this.setSessionAttr("posts",userInfo.get("posts"));
        this.setSessionAttr("allTimes",userInfo.get("all_times"));
        this.setSessionAttr("money",userInfo.get("money"));
        this.setSessionAttr("state",userInfo.get("state"));
        this.setSessionAttr("examGrade",userInfo.get(""));
        this.setSessionAttr("qq",userInfo.get("qq"));
      }
      //加载个人主页相关信息
     
      //设置会话参数
      this.setSessionAttr("userName", userName);
View Full Code Here

      File luceneLocalFile = new File(filePath);
      if(!luceneLocalFile.exists()) {
        luceneLocalFile.createNewFile();
      }
      fw = new FileWriter(filePath);
      JSONObject articleJsonObj = JSONObject.fromObject(article);
      String outPutStr = articleJsonObj.toString();
        char buffer[] = outPutStr.toCharArray();
        fw.write(buffer, 0, buffer.length);
        fw.flush();
    } catch (Exception e) {
      log.info("txt文件写出错误");
View Full Code Here

      }else{
        ja=JSONArray.fromObject(o);
      }
      this.outJsonString(ja.toString());
    }else{
      JSONObject jo=null;
      if(isInjectDefaultConvertHandler){
        jo=JSONObject.fromObject(o,getJsonConfig(null));
      }else{
        jo=JSONObject.fromObject(o);
      }
      this.outJsonString(jo.toString());
    }
  }
View Full Code Here

   * Date:2011-4-1 下午05:42:41
   * @param success
   * @param message
   */
  public void outSimpleMessage(boolean success,String message){
    JSONObject jo=new JSONObject();
    jo.accumulate("success", success);
    jo.accumulate("message", message);
    this.outJsonString(jo.toString());
  }
View Full Code Here

   * @param success
   * @param message
   * @param isInjectDefaultConvertHandler 是否注入默认对象转换类
   */
  public void outResultMessage(Object result,String message,boolean isInjectDefaultConvertHandler){
    JSONObject jo=new JSONObject();
    Object o=null;
    if(Collection.class.isInstance(result)||result.getClass().isArray()){
      if(isInjectDefaultConvertHandler){
        o=JSONArray.fromObject(result, this.getJsonConfig(null));
      }else{
        o=JSONArray.fromObject(result, this.getJsonConfig(null));
      }
    }else{
      if(isInjectDefaultConvertHandler){
        o=JSONObject.fromObject(result,this.getJsonConfig(null));
      }else{
        o=JSONObject.fromObject(result);
      }
    }
    jo.accumulate("success", true);
    jo.accumulate("item", o);
    jo.accumulate("message", message);
    this.outJsonString(jo.toString());
  }
View Full Code Here

    @SuppressWarnings("unchecked")
    public static void toJsonObjectList(List attrList, HttpServletResponse response){
        String jsonStr = "[";
        for (Object attrMap : attrList) {
            JSONObject json = JSONObject.fromObject(attrMap);
            jsonStr = jsonStr + json.toString() + ',';
        }
        jsonStr = jsonStr + "{ } ]";
        if (UtilValidate.isEmpty(jsonStr)) {
            Debug.logError("JSON Object was empty; fatal error!",module);
        }
View Full Code Here

        josonMap.clear();
        return "success";
    }
   
    public static void toJsonObject(Map<String,Object> attrMap, HttpServletResponse response){
        JSONObject json = JSONObject.fromObject(attrMap);
        String jsonStr = json.toString();
        if (jsonStr == null) {
            Debug.logError("JSON Object was empty; fatal error!",module);
        }
        // set the X-JSON content type
        response.setContentType("application/json");
View Full Code Here

            Debug.logError("Unable to get response writer",module);
        }
    }
   
    public static void toJsonObjectList(List<Map<String,Object>> list, HttpServletResponse response) throws EventHandlerException {
        JSONObject json = null;
        List<JSONObject> jsonList = new ArrayList<JSONObject>();
        if (list != null) {
            for (Map<String,Object> val : list) {
                json = new JSONObject();
                for (String rowKey: val.keySet()) {
                    json.put(rowKey, val.get(rowKey));
                }
                jsonList.add(json);
            }
            String jsonStr = jsonList.toString();
            if (jsonStr == null) {
View Full Code Here

TOP

Related Classes of net.sf.json.JSONObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.