2010-03-31 61 views
2

我需要为Google App Engine项目注册自定义ELResolverGAE/J:无法注册自定义ELResolver

由于收到的任何请求之前,必须先进行注册,as specified by the Javadoc

It is illegal to register an ELResolver after the application has received any request from the client. If an attempt is made to register an ELResolver after that time, an IllegalStateException is thrown.

我使用的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()回报总是空。我已经填写了一份错误报告。任何想法的解决方法?

回答

4

我不确定哪个servletcontainer GAE使用“引擎盖下”(Jetty?Tomcat?),但这在Tomcat 6.x中可以识别为bug。一个解决办法是强制自己JspRuntimeContext加载获取出厂前:

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

看是否有此或类似的黑客帮助。

+0

不错!现在我得到一个'java.lang.AbstractMethodError:javax.servlet.jsp.JspFactory.getJspApplicationContext(Ljavax/servlet/ServletContext;)Ljavax/servlet/jsp/JspApplicationContext;'异常。 JSP版本是2.0,其中'getApplicationContext()'是为JSP 2.1定义的。我绝对不走运 – dfa 2010-03-31 12:21:15

+1

'ELResolver'也是JSP 2.1。 GAE真的是JSP 2.0吗?我期望它是JSP 2.1。你的'web.xml'声明为Servlet 2.5吗?示例在这里:http://snipplr.com/view/3775/minimal-webxml-webapp-descriptor-version-25/ – BalusC 2010-03-31 12:27:10

+0

2.5,当然:) – dfa 2010-03-31 13:18:55