【The "
web.xml"
is called web application deployment descriptor】行是知之始,知是行之成。这篇文章主要讲述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 "webappshelloservletWEB-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> webappshelloservletWEB-INFweb.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 ishttp://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).
推荐阅读
- AutoMapper 的简单使用
- 小程序分享链接功能 - onShareAppMessage
- 使用ADB命令写Android自动化测试脚本
- springboot打包后静态资源webapp文件夹无法打包进去
- AndroidStudio下载安装教程(图文教程)
- app性能测试
- Virtualenvwrapper 安装 for Mac
- Android 开发中使用 Recyclerview
- CMS Web设计(动态内容应用程序指南)