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. 用BERT做语义相似度匹配任务:计算相似度的方式

    1. 自然地使用[CLS] 2. cosine similairity 3. 长短文本的区别 4. sentence/word embedding 5. siamese network 方式 1. 自 ...

  2. PTA 8-1 jmu-java-流、文件与正则表达式 (5 分)

    0.字节流与文件 我的代码: public static byte[] readFile(String path){ File file = new File(path); FileInputStre ...

  3. C++实现16进制字符串转换成int整形值

    开发中经常需要把16进制字符串转换成整形,写了个个代码供大家参考下: #include <stdio.h> #include <string.h> //字符转换成整形 int ...

  4. ubuntu内lnmp相关操作命令

    LNMP状态管理命令: **LNMP状态管理:** sudo lnmp {start|stop|reload|restart|kill|status} **Nginx状态管理:**sudo /etc/ ...

  5. c++学习(二)------this指针学习

    在c++中,类的不同实例有自己的数据(储存在不同地方),有很多拷贝.而类的成员函数却只有一份备份. 而不同的类的实例却可以调用同一个函数,这是通过this指针来完成的. *this代表当前类本身,th ...

  6. Struts2中OGNL表达式的用法

    今天分享的是Struts2框架中的一种ognl表达式语言,主要分两个目标去学习    1.理解struts2传值的优先级    2.ognl与el的区别 一:ognl表达式语言简介 OGNL的全称是O ...

  7. nodejs 对 png 图片的像素级别处理

    使用node对图片的像素进行处理 这里使用常见的图片灰度处理为例子: 用到了 pngjs 的 npm 库,这个库可以将 png 的图片文件 Buffer 流,转换为 r g b a 为 255 的像素 ...

  8. JS强制关闭浏览器页签并且不提示关闭信息

    工作中很多奇葩的需求都会出现,现在就有一个问题,描述如下: 现在的登录跳转权限页面要去掉,集成在第三方系统信息上,当退出登录的时候需要关掉打开的Tab页面,因此考虑使用window.close()关闭 ...

  9. 15-MySQL DBA笔记-运维管理

    第15章 运维管理 随着各种技术的快速发展,现今的DBA可以比以前的DBA维护多得多的数据库实例.DBA已经越来越像一个资源的管理者,而不是简单的操作步骤执行人.本章将为读者介绍规模化运维之道.首先, ...

  10. 洛谷 P1307 数字反转

    链接:https://www.luogu.org/problem/P1307 题目: 题目描述 给定一个整数,请将该数各个位上数字反转得到一个新数.新数也应满足整数的常见形式,即除非给定的原数为零,否 ...