为什么要使用 web.xml? [英] Why do we use web.xml?

查看:29
本文介绍了为什么要使用 web.xml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

web.xml 有什么用,为什么要使用?

What is the use of web.xml and why do we use?

<filter>
        <filter-name>wicket.mysticpaste</filter-name>
        <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
        <init-param>
            <param-name>applicationClassName</param-name>
            <param-value>com.mysticcoders.WicketApplication</param-value>
        </init-param>
    </filter>

 <filter-mapping>
  <filter-name>wicket.mysticpaste</filter-name>
    <url-pattern>/*</url-pattern>
 </filter-mapping>

这个文件管理器和文件映射有什么作用?

What does this filer and filermapping do?

推荐答案

一般来说,这是java中web应用的配置文件.它指示 servlet 容器(例如 tomcat)加载哪些类,在上下文中设置哪些参数,以及如何拦截来自浏览器的请求.

Generally speaking, this is the configuration file of web applications in java. It instructs the servlet container (tomcat for ex.) which classes to load, what parameters to set in the context, and how to intercept requests coming from browsers.

您指定:

  • 您要使用哪些 servlet(和过滤器)以及要将它们映射到哪些 URL
  • 侦听器 - 发生某些事件(上下文开始、会话创建等)时通知的类
  • 配置参数(上下文参数)
  • 错误页面、欢迎文件
  • 安全约束

在 servlet 3.0 中,许多 web.xml 部分是可选的.这些配置可以通过注解来完成(@WebServlet, @WebListener)

In servlet 3.0 many of the web.xml parts are optional. These configurations can be done via annotations (@WebServlet, @WebListener)

这篇关于为什么要使用 web.xml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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