小编Bob*_*Rob的帖子

如何在没有web.xml的情况下以编程方式设置session-timeout,error-pages

我正在使用Spring MVC并成功设置了一个WebApplicationInitializer(使用Tomcat的ServletContainerInitializer),没有任何web.xml文件.添加过滤器(如Spring Security)和servlet(如Dispatcher)是没有问题的,它们工作正常.如果我需要,我也可以设置init-params.

我无法弄清楚的是如何设置web.xml中通常存在的一些特殊标记.例如,我想设置一个自定义403错误页面.通常我会在web.xml中执行以下操作:

<error-page>
    <error-code>403</error-code>
    <location>/accessDenied.html</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)

但我无法弄清楚如何在WebApplicationInitializer(可以访问ServletContext)中执行此操作.

我对session-timeout和welcome-files有同样的问题.我已经搜索了大约两天,但仍然没有看到这个以编程方式完成.同样,目标是完全删除web.xml文件并改为使用初始化程序类.

有任何想法吗?

spring spring-mvc

10
推荐指数
1
解决办法
8950
查看次数

标签 统计

spring ×1

spring-mvc ×1