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 阅读(825) 评论(1)  编辑  收藏

评论

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

aaaaaaaaaaaaaaaaaaaaaaadddddddddd
  回复  更多评论    

只有注册用户登录后才能发表评论。


网站导航: