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. JS CSS写下拉菜单 竖行

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 创建Webpack 4.X项目

    创建基本的webpack4.x项目 运行npm init -y 快速初始化项目 在项目根目录创建src源代码目录和dist产品目录 在 src 目录下创建 index.html 使用 cnpm 安装 ...

  3. eNSP——利用三层交换机实现VLAN间路由

    原理: VLAN将一个物理的LAN在逻辑上划分成多个广播域.VLAN内的主机间可以直接通信,而VLAN间不能直接互通. 在现实网络中,经常会遇到需要跨VLAN相互访问的情况,工程师通常会选择一些方法来 ...

  4. Temporal IR (Chapter3 -Temporal Infroamtion Extraction)

    不管是文档,还是查询中,都显式或者隐式地包含了可以被利用的时间信息. 提取出来的时间信息可以用作构成“时间简历”(temporal profile)用于多种对象,比如实体和事件. 在时间信息中,最容易 ...

  5. 解决maven项目无法读取src/main/java目录下面的配置文件问题

    我们在用Mybatis去操作底层数据库的时候,需要用到xml配置文件,一般我们是把配置文件和dao放置在同一层目录. 但是在用idea操作maven项目的时候,我们可能会遇到无法读取到dao对应的ma ...

  6. go 常量2

    数值常量 数值常量是高精度的 _值_. 一个未指定类型的常量由上下文来决定其类型. 也尝试一下输出 needInt(Big) 吧. package main import "fmt" ...

  7. gin PostForm 方法不起作用

    情景: 在httpie post 下,在 axios post下,总的来说,就是在form-data下只有c.Bind()会有用 如果一定要用c.PostForm() headers必须为x-www- ...

  8. SpringBoot 第二篇:SpringBoot配置文件使用

    背景 项目跑起来,和以前相比,现在的配置文件能干什么?SpringBoot 项目的配置文件就是创建项目时,自带的 application.properties ,打开里面空空如也.这个文件里面的语法是 ...

  9. MySQL 触发器的使用

    MySQL 基础篇 三范式 MySQL 军规 MySQL 配置 MySQL 用户管理和权限设置 MySQL 常用函数介绍 MySQL 字段类型介绍 MySQL 多列排序 MySQL 行转列 列转行 M ...

  10. C++新特性---智能指针

    智能指针:     为什么需要智能指针?         1. malloc出来的空间,没有进行释放,存在内存泄漏的问题.          2. 异常安全问题.如果在malloc和free之间如果存 ...