如何定义< welcome-file-list>和< error-page>在servlet 3.0的web.xml中? [英] How to define <welcome-file-list> and <error-page> in servlet 3.0's web.xml-less?

查看:126
本文介绍了如何定义< welcome-file-list>和< error-page>在servlet 3.0的web.xml中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有现有的web-app,我想将其转换为web.xml-less servlet 3.0。我已经设法使它工作,但是web.xml中有2个标签,我仍然不知道web.xml-less环境中的等效代码。

I have existing web-app which I want to convert into web.xml-less of servlet's 3.0. I've managed to make it working, however there are 2 tags in web.xml which I still don't know the equivalent code in web.xml-less environment.

<welcome-file-list>
    <welcome-file>/index.jsp</welcome-file>
</welcome-file-list>

<error-page>
    <error-code>404</error-code>
    <location>/pageNotFound</location>
</error-page>

感谢任何帮助

推荐答案

在Servlets 3.0中,在很多情况下你不需要web.xml,但是,有时它是必需的或者只是有用的。您的案例只是其中之一 - 没有特殊的注释来定义欢迎文件列表或错误页面。

In Servlets 3.0 you don't need a web.xml for many cases, however, sometimes it's required or just useful. Your case is just one of them - there is no special annotations to define welcome-file list or error-pages.

另一件事是 - 你真的想拥有它们吗?硬编码?基于注释/程序的配置和XML中的声明性配置有一些有效的用例。转移到Servlets 3.0并不一定意味着不惜一切代价摆脱web.xml。

Another thing is - would you really like to have them hardcoded? There are some valid use-cases for annotation / programmatic based configuration and for declarative configuration in XML. Moving to Servlets 3.0 doesn't necessarily means getting rid of web.xml at all cost.

我会发现你发布的条目是XML中更好的配置示例。首先 - 它们可以从部署更改为部署,其次 - 它们会影响整个应用程序,而不会影响任何特定的Servlet。

I would find the entries you posted a better example of configuration in XML. Firstly - they can be changed from deployment to deployment and secondly - they affect whole application and not any particular Servlet.

这篇关于如何定义&lt; welcome-file-list&gt;和&lt; error-page&gt;在servlet 3.0的web.xml中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆