How to configure <context-param> programmatically without web.xml

邮差的信 提交于 2019-11-30 15:37:10

Since Servlet 3.0, you can programmatically set them via ServletContext#setInitParameter().

Just put below ServletContextListener anywhere in your web project. The @WebListener annotation will make the container to automatically pickup and run it during webapp startup.

@WebListener
public class Config implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent event) {
        ServletContext servletContext = event.getServletContext(); 
        servletContext.setInitParameter("com.sun.faces.numberOfLogicalViews", "10");
    }

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

}

If you're using embedded Tomcat, it is like this:

Context.getServletContext()
    .getServletRegistrations()
    .get("webdavservlet")
    .setInitParameter("listings", "true");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!