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

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

  1. web.xml中使用web前缀配置无法访问controller

    <web:context-param> <web:param-name>contextConfigLocation</web:param-name> <web ...

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

    <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns="http://w ...

  3. web.xml的说明

    <!--DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. Copyright 2000-2007 Sun Microsystems ...

  4. Analysis of Web.xml in Hello1 project

    一.web.xml文件介绍 The web.xml file contains several elements that are required for a Facelets applicatio ...

  5. Descriptors;Hello1 project中的Web.xml

    Deployment Descriptors(描述符)是一个xml文件,用来描述如何部署一个模块或者应用(根据描述符中定义的配置和容器选项).举例来说,一个EJB的部署描述符会向EJB容器传递如何管理 ...

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

    点击下面连接查看从零开始搭网站全系列 从零开始搭网站 上一章我们在CentOS下搭建了Tomcat,但是还是没有跑起来...那么这一章就把最后的配置给大家放上去. 有两种方式:一种是用 rm -f 给 ...

  7. web.xml文件的 xsd引用(或dtd引用)学习

    1. 为什么web.xml会有不同版本的xsd引用: JDK依赖变化: 或 servlet(JAVA EE)自身API的改变: 2. 为什么会有dtd和xsd两个版本的区别 我是在这篇文章中看到的,作 ...

  8. Java Web的web.xml文件作用及基本配置(转)

    其实web.xml就是asp.net的web.config一个道理. 说明: 一个web中完全可以没有web.xml文件,也就是说,web.xml文件并不是web工程必须的. web.xml文件是用来 ...

  9. spring web.xml 难点配置总结

    web.xml web.xml是所有web项目的根源,没有它,任何web项目都启动不了,所以有必要了解相关的配置. ContextLoderListener,ContextLoaderServlet, ...

随机推荐

  1. uniapp跨域两次请求解决方案

    引入qs模块 使用 qs模块将data序列化,再传递,注意header必须设置为 'content-type':'application/x-www-form-urlencoded', import ...

  2. nginx 工作原理总结

    1.  Nginx的模块与工作原理 Nginx由内核和模块组成,其中,内核的设计非常微小和简洁,完成的工作也非常简单,仅仅通过查找配置文件将客户端请求映射到一个location block(locat ...

  3. 20175316 盛茂淞 2018-2019-2 《Java程序设计》实验三《敏捷开发与XP实践》 实验报告

    实验内容与要求 1.XP基础 极限编程(Extreme Programming,XP)是一种全新而快捷的软件开发方法.XP团队使用现场客户.特殊计划方法和持续测试来提供快速的反馈和全面的交流: XP是 ...

  4. typescript无法识别vue中的$refs

    例如:vue-fullscreen <template> <div class="Test"> <fullscreen ref="fulls ...

  5. 什么是H5?

    总听到很多人说H5,现在H5很火,到底H5是什么,以下发表个人对H5的理解. HTML5 将成为 HTML.XHTML 以及 HTML DOM 的新标准. HTML 的上一个版本诞生于 1999 年. ...

  6. K8S踩坑篇-master节点作为node节点加入集群

    前面我们二进制部署K8S集群时,三台master节点仅仅作为集群管理节点,所以master节点上中并未部署docker.kubelet.kube-proxy等服务.后来我在部署mertics-serv ...

  7. sqlite lib导入

    依赖 1.System.Data.SQLite 2.SqlKata //https://www.nuget.org/profiles/SQLite //http://system.data.sqlit ...

  8. 帮助理解Docker,生动装逼介绍Docker

    为了帮助理解Docker,整理了一下 Docker组成的三个基本概念: 仓库(Repository) 镜像(Image) 容器(Container) 仓库:(Repository)——集中存放镜像文件 ...

  9. python 手机App数据抓取实战二抖音用户的抓取

    前言 什么?你问我国庆七天假期干了什么?说出来你可能不信,我爬取了cxk坤坤的抖音粉丝数据,我也不知道我为什么这么无聊. 本文主要记录如何使用appium自动化工具实现抖音App模拟滑动,然后分析数据 ...

  10. Merkle树

    在分布式系统.P2P应用中或者是区块链中,会经常使用一种数据结构Merkle tree(默克尔树),这里我们将详细讨论一下这个常用数据结构. Merkle tree Merkle树看起来非常像二叉树, ...