samtiger


          QQ:418148757
          Name:yangchuan
          數據加載中……
          struts2的小bug

          struts2.1.6的時候,有編碼問題,主要是因為他把設置編碼的那行代碼沒放在最前面。
          struts2.2.1的時候,又出來一個低級bug,那就是一直以來模板的加載都是先查找web.xml中查抄templatePath的配置值,然后才從web應用目錄查找,最后才是從class和jar中查找。結果在2.2.1中就犯了一個低級bug,那就是永遠找不到web應用目錄中,代碼在:org.apache.struts2.views.freemarker.FreemarkerManager.class中
              
          public void init(ServletContext servletContext) throws TemplateException {
              this.config = createConfiguration(servletContext);

              this.config.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
              this.contentType = "text/html";

              this.wrapper = createObjectWrapper(servletContext);
              if (LOG.isDebugEnabled())
                LOG.debug("Using object wrapper of class " + this.wrapper.getClass().getName(), new String[0]);

              this.config.setObjectWrapper(this.wrapper);

              this.templatePath = servletContext.getInitParameter("TemplatePath");
              if (this.templatePath == null)
                this.templatePath = servletContext.getInitParameter("templatePath");

              if (this.templatePath == null)
                this.templatePath = "class://";
              this.config.setTemplateLoader(createTemplateLoader(servletContext, this.templatePath));

              loadSettings(servletContext);
            }
              
          protected TemplateLoader createTemplateLoader(ServletContext servletContext, String templatePath)
            {
              TemplateLoader templatePathLoader = null;
              try
              {
                if (templatePath.startsWith("class://"))
                {
                  templatePathLoader = new ClassTemplateLoader(super.getClass(), templatePath.substring(7));
                } else if (templatePath.startsWith("file://"))
                  templatePathLoader = new FileTemplateLoader(new File(templatePath));
              }
              catch (IOException e) {
                LOG.error("Invalid template path specified: " + e.getMessage(), e, new String[0]);
              }

              if (templatePathLoader != null);
              return new MultiTemplateLoader(new TemplateLoader[] { new WebappTemplateLoader(servletContext), new StrutsClassTemplateLoader() });
            }

          不過,這個問題已經在2.3的版本中修復過來了。

          posted on 2012-04-10 23:13 sam.chuan.yang 閱讀(850) 評論(1)  編輯  收藏

          評論

          # re: struts2的小bug 2013-01-22 12:56 123213

          aaaaaaaaaaaaaaaaaaaaaaadddddddddd
            回復  更多評論    

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 胶州市| 吴忠市| 瓮安县| 吴桥县| 亳州市| 琼结县| 武邑县| 伊川县| 昆明市| 美姑县| 繁峙县| 鄂托克旗| 华安县| 内黄县| 饶河县| 扎兰屯市| 连云港市| 大宁县| 黔东| 苍溪县| 新密市| 来安县| 南皮县| 邛崃市| 齐河县| 麦盖提县| 贵南县| 忻城县| 察哈| 广饶县| 郁南县| 苗栗市| 阿拉善右旗| 且末县| 灵璧县| 慈溪市| 北海市| 江北区| 织金县| 瓮安县| 保山市|