The "web.xml" is called web application deployment descriptor

3.3  Configure the Application Deployment Descriptor - "web.xml"

A web user invokes a servlet, which is kept in the web server, by issuing a specific URL from the browser. In this example, we shall configure the following request URL to trigger the "HelloServlet":

http://hostname:port/helloservlet/sayhello

Create a configuration file called "web.xml", and save it under "webapps\helloservlet\WEB-INF", as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app version="3.0"
  xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

  <!-- To save as <CATALINA_HOME>\webapps\helloservlet\WEB-INF\web.xml -->

   <servlet>
      <servlet-name>HelloWorldServlet</servlet-name>
      <servlet-class>mypkg.HelloServlet</servlet-class>
   </servlet>

   <!-- Note: All <servlet> elements MUST be grouped together and
         placed IN FRONT of the <servlet-mapping> elements -->

   <servlet-mapping>
      <servlet-name>HelloWorldServlet</servlet-name>
      <url-pattern>/sayhello</url-pattern>
   </servlet-mapping>
</web-app>
  • The "web.xml" is called web application deployment descriptor. It provides the configuration options for that particular web application, such as defining the the mapping between URL and servlet class.
  • The above configuration defines a servlet named "HelloWroldServlet", implemented in "mypkg.HelloServlet.class" (written earlier), and maps to URL "/sayhello", where "/" denotes the context root of this webapp "helloservlet". In other words, the absolute URL for this servlet is http://hostname:port/helloservlet/sayhello.
  • Take note that EACH servlet requires a pair of <servlet> and <servlet-mapping> elements to do the mapping, via an arbitrary but unique <servlet-name>. Furthermore, all the <servlet> elements must be grouped together and placed before the <servlet-mapping> elements (as specified in the XML schema).

https://www.ntu.edu.sg/home/ehchua/programming/java/JavaServlets.html

原文地址:https://www.cnblogs.com/feng9exe/p/12085041.html

时间: 2024-08-02 12:18:20

The "web.xml" is called web application deployment descriptor的相关文章

[从零搭网站五]http网站Tomcat配置web.xml和server.xml

点击下面连接查看从零开始搭网站全系列 从零开始搭网站 上一章我们在CentOS下搭建了Tomcat,但是还是没有跑起来...那么这一章就把最后的配置给大家放上去. 有两种方式:一种是用 rm -f 给这两个文件删掉,再用vim建新的出来.另一种是vim编辑,输入:set nu 显示行号,再输入:1,最后一行的行号d 把全文删掉. 然后再复制粘贴我给你们的配置文件就行. web.xml  , 完全不用修改,直接复制就行了: <?xml version="1.0" encoding=

web.xml中servlet-mapping的url-pattern的配置

在配置web.xml的servlet-mapping 的 url-pattern 碰到问题, 上网查, 查到servelt2_2-spec.pdf才得到答案. 结论:  ? '/XXX/*' ? '*.html' ? '/' ? 其他都是精确映射 例: '/XXX/Y*.html' 只能映射/XXX/Y*.html 的URL请求. 例: '/XXX' 只可以映射/XXX的URL请求. 引用 10.2 Specification of Mappings In the web application

javaWeb项目中web.xml的xsd( XML Schemas Definition)文件

<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://java.sun.com/xml/ns/javaee" xmlns:javaee="http://java.sun.com/xml/ns/javaee" xml

web.xml of hello1 analysis

一.web.xml文件介绍 The web.xml file contains several elements that are required for a Facelets application. All of the following are created automatically when you use NetBeans IDE to create an application. web.xml文件的作用 web.xml主要用来配置Filter.Listener.Servle

web.xml是tomcat和spring间的桥梁,是tomcat构建spring运行环境的说明书

It is a web application deployment descriptor file, contains detail description about web application like configuration of Servlet, Session management, Startup parameters, Welcome file..etc. We can not change the directory or extension name of this 

Tomcat(一):Tomcat启动时加载web.xml

server.xml配置文件样例: <?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional inf

web.xml详解

web.xml的作用 web.xml,一个Tomcat工程中最重要的配置文件.web.xml没有其实也可以----只要你确定你的项目里面不需要任何过滤器.监听器.Servlet等等.我试了一下,没有web.xml对那些已经编译成Servlet的jsp页面来说,是不影响正常显示的,但是那些没有编译成Servlet的jsp页面,访问的时候就会报500的错误了.下面逐一看一下web.xml里常用标签的作用. welcome-file-list 这个标签是用来配置首页用的: <welcome-file-

是时候抛弃web.xml了?

你是否再为配置文件web.xml容易出错而烦恼?是否为web.xml文件存放位置而不知所措?是否为web.xml为什么要这样配?怎么才能更好的配置web.xml而烦恼?那么一种新的方式出现了: spring提供了支持servlet 3+以上的编程方式,它可以替换或者和web.xml共存的方式工作.其相关类如下: 1.WebApplicationInitializer 传统上,我们基于web.xml这种方式来配置web应用,而WebApplicationInitializer的实现支持在servl

web.xml文件的作用及基本配置

Java的web工程中的web.xml文件有什么作用呢?它是每个web工程都必须的吗? 一个web中完全可以没有web.xml文件,也就是说,web.xml文件并不是web工程必须的. 那什么时候需要,什么时候可以不需要呢? 要想回答上面的问题,得先了解web.xml文件是用来干什么的.web.xml文件是用来配置:欢迎页.servlet.filter等的.当你的web工程没用到这些时,你可以不用web.xml文件来配置你的web工程. 那么web.xml能做的所有事情都有那些? 其实,web.