Example #1
0
  /**
   * 使用模板渲染
   *
   * @param template 模板名稱
   * @param dataModel 模板參數
   */
  public <T> void render(String template, Map<String, T> dataModel) {
    try {
      if (dataModel == null) dataModel = new HashMap<String, T>();

      dataModel.put("contextPath", (T) getContextPath(request));
      // 模板中传入session值
      HttpSession session = request.getSession();
      String[] sessionName = session.getValueNames();
      for (String name : sessionName) {
        dataModel.put(name, (T) request.getSession().getAttribute(name));
      }
      // 模板中传入request值
      Map paramMap = request.getParameterMap();
      for (Iterator itor = paramMap.keySet().iterator(); itor.hasNext(); ) {
        Object key = itor.next();
        Object object = paramMap.get(key);
        if (key instanceof String && object != null) {

          if (object.getClass().isArray()) {
            Object[] sValue = (Object[]) object;
            String value = sValue[0].toString();
            if (value.trim().isEmpty()) continue;
            dataModel.put(key.toString(), (T) value);
          }
        }
      }
      String result = FreeMarkerTool.getSingleton().getTemplateResult(template, dataModel);
      response.getWriter().write(result);
    } catch (Exception e) {
      logger.error(e.getMessage(), e);
    }
  }
Example #2
0
 /**
  * 同步数据到redis
  *
  * @author 杨雪令
  * @time 2016年5月18日上午11:46:03
  * @version 1.0
  */
 public void syncToRedis() {
   if (this.key == null || this.key.length() < 1) return;
   Map<String, Object> paramMap = new HashMap<String, Object>();
   for (String valueName : httpSession.getValueNames()) {
     paramMap.put(valueName, httpSession.getAttribute(valueName));
   }
   JedisUtil.set(this.key, paramMap, timeout * 60);
 }
 /** {@inheritDoc} */
 @SuppressWarnings("deprecation")
 public int size() {
   return session != null ? session.getValueNames().length : 0;
 }
Example #4
0
 @SuppressWarnings("deprecation")
 @Override
 public String[] getValueNames() {
   syncFromRedis();
   return httpSession.getValueNames();
 }
Example #5
0
 @Override
 public String[] getValueNames() {
   return sess.getValueNames();
 }