为什么我们使用web.xml?

[英]Why do we use web.xml?


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

web.xml有什么用?我们为什么要使用?

<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?

这个文件管理器和filemapping做了什么?

6 个解决方案

#1


61  

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.

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

There you specify:

在那里你指定:

  • what servlets (and filters) you want to use and what URLs you want to map them to
  • 您想要使用哪些servlet(和过滤器)以及要将它们映射到哪些URL
  • listeners - classes that are notified when some events happen (context starts, session created, etc)
  • 侦听器 - 在某些事件发生时通知的类(上下文启动,会话创建等)
  • configuration parameters (context-params)
  • 配置参数(context-params)
  • error pages, welcome files
  • 错误页面,欢迎文件
  • security constriants
  • 安全行为人

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

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

#2


5  

The web.xml file is the deployment descriptor for a Servlet-based Java web application (which at most Java web apps are). Among other things, it declares which Servlets exist and which URLs they handle.

web.xml文件是基于Servlet的Java Web应用程序(大多数Java Web应用程序都是)的部署描述符。除此之外,它还声明了哪些Servlet存在以及它们处理哪些URL。

The part you cite defines a Servlet Filter. Servler filters can do all kinds of preprocessing on requests. Your specific example is a filter hat the Wicket framework uses as its entry point for all requests, because filters are in some way more powerful that Servlets.

您引用的部分定义了Servlet过滤器。 Servler过滤器可以对请求进行各种预处理。您的具体示例是Wicket框架用作所有请求的入口点的过滤器,因为过滤器在某种程度上比Servlet更强大。

#3


1  

It says all the requests to go through WicketFilter

它说明了通过WicketFilter的所有请求


Also, if you use wicket WicketApplication for application level settings. Like URL patterns and things that are true at app level

此外,如果您使用wicket WicketApplication进行应用程序级别设置。像URL模式和在应用程序级别真实的东西


This is what you need really, http://wicket.apache.org/learn/examples/helloworld.html

这就是你真正需要的,http://wicket.apache.org/learn/examples/helloworld.html

#4


0  

It's the default configuration for a Java web application; it's required.

它是Java Web应用程序的默认配置;这是必需的。

WicketFilter

is applied to every HTTP request that's sent to this web app.

适用于发送到此Web应用程序的每个HTTP请求。

#5


0  

Web.xml is called as deployment descriptor file and its is is an XML file that contains information on the configuration of the web application, including the configuration of servlets.

Web.xml称为部署描述符文件,它是一个XML文件,其中包含有关Web应用程序配置的信息,包括servlet的配置。

#6


0  

Servlet to be accessible from a browser, then must tell the servlet container what servlets to deploy, and what URL's to map the servlets to. This is done in the web.xml file of your Java web application.

可以从浏览器访问Servlet,然后必须告诉servlet容器要部署哪些servlet,以及将servlet映射到的URL。这是在Java Web应用程序的web.xml文件中完成的。

use web.xml in servlet

在servlet中使用web.xml

<servlet>
    <description></description>
    <display-name>servlet class name</display-name>
    <servlet-name>servlet class name</servlet-name>
    <servlet-class>servlet package name/servlet class name</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>servlet class name</servlet-name>
    <url-pattern>/servlet class name</url-pattern>
</servlet-mapping>

manly use web.xml for servlet mapping.

manly使用web.xml进行servlet映射。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2010/12/27/2ff2b586d645637795da995273bb395c.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号