2016-07-25 56 views
0

在我的項目中,我重寫了一些擴展爲javax.el.ELResolver(3.0版)的函數。我把在類JSF faces-config.xml配置文件中:如何在不使用JSF的情況下配置ELResolver

<application> 
    <el-resolver>com.myapp.common.el.SectionELResolver</el-resolver> 
</application> 

現在,我想刪除JSF框架,但讓我ELResolver的配置。如何配置? 如何編寫servlet以及如何在web.xml中進行配置?

回答

1

您只能通過JspApplicationContext#addELResolver()以編程方式執行此操作。沒有web.xml支持這個。您可以使用ServletContextListener執行任務。

@WebListener 
public class ApplicationListener implements ServletContextListener { 

    @Override 
    public void contextInitialized(ServletContextEvent event) { 
     JspFactory.getDefaultFactory() 
        .getJspApplicationContext(event.getServletContext()) 
        .addELResolver(new SectionELResolver()); 
    } 

    @Override 
    public void contextDestroyed(ServletContextEvent event) { 
     // NOOP. 
    } 

} 
相關問題