代码之家  ›  专栏  ›  技术社区  ›  dfa

GAE/J:无法注册自定义ELResolver

  •  2
  • dfa  · 技术社区  · 15 年前

    我需要注册一个海关 ELResolver 谷歌应用引擎项目。

    因为它必须在收到任何请求之前注册, as specified by the Javadoc :

    在应用程序 收到客户的任何请求。如果试图注册 在该时间之后,将引发IllegalstateException。

    我使用的是servletContextListener:

    public class RegisterCustomELResolver implements ServletContextListener { 
    
        @Override 
        public void contextInitialized(ServletContextEvent sce) { 
            ServletContext context = sce.getServletContext(); 
            JspApplicationContext jspContext = 
                JspFactory.getDefaultFactory().getJspApplicationContext(context); 
            jspContext.addELResolver(new MyELResolver()); 
        } 
    
        ... 
    }
    

    问题是 JspFactory.getDefaultFactory() 返回始终为空。我已经填了一份虫子报告。有什么解决办法吗?

    1 回复  |  直到 15 年前
        1
  •  4
  •   BalusC    15 年前

    我不确定哪个servletcontainer gae使用“引擎盖下”(jetty?汤姆猫?),但可以将其识别为 bug 在Tomcat 6.x中,解决方法是强制加载 JspRuntimeContext 你自己去工厂之前:

    Class.forName("org.apache.jasper.compiler.JspRuntimeContext");
    

    看看这个或类似的黑客是否有用。