zoukankan      html  css  js  c++  java
  • 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 is http://hostname:port/helloservlet/sayhello.Servlet_HelloServletURL.png
    • 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

  • 相关阅读:
    google搜索引擎使用方法
    通过Ajax和SpringBoot交互的示例
    利用html sessionStorge 来保存局部页面在刷新后回显,保留
    JS页面刷新保持数据不丢失
    Firefox浏览器中,input输入框输入的内容在刷新网页后为何还在?
    关于form/input 的autocomplete="off"属性
    Java对日期Date类进行加减运算,年份加减,月份加减
    select标签设置只读的方法(下拉框不可选但可传值)
    用Thymeleaf在前台下拉列表取值
    jsp页面动态展示list-使用<select>和<c:forEach>标签
  • 原文地址:https://www.cnblogs.com/feng9exe/p/12085041.html
Copyright © 2011-2022 走看看