1. 程式人生 > >Java之servlet三

Java之servlet三

web.xml配置

servlet

<servlet>
    <servlet-name>ServletDemo1</servlet-name>
    <servlet-class>com.yuan.servlet.ServletDemo1</servlet-class>
    <load-on-startup>1</load-on-startup>
    <init-param>
        <param-name>name</param-name>
        <param-value>yuan</param-value>
    </init-param>
</servlet>

  <servlet-name>      servlet註冊名

  <servlet-class>       servlet註冊類

  <load-on-startup>   啟動載入servlet順序,0表示不載入

  <init-param>           servlet初始化引數

servlet-mapping

<servlet-mapping>
    <servlet-name>ServletDemo1</servlet-name>
    <url-pattern>/ServletDemo1</url-pattern>
</servlet-mapping>

<url-pattern>            對映servlet的url

context-param

<context-param>
    <param-name>url</param-name>
    <param-value>jdbc:mysql://localhost:3306/test</param-value>
</context-param>

 <param-name>     引數名

 <param-value>     引數值

附錄

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                      http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
  version="3.1">
  
    <context-param>
        <param-name></param-name>
        <param-value></param-value>
    </context-param>
    
    <listener>
        <listener-class></listener-class>
    </listener>
    
    <servlet>
        <servlet-name></servlet-name>
        <servlet-class></servlet-class>
        <init-param>
            <param-name></param-name>
            <param-value></param-value>
        </init-param>
        <load-on-startup></load-on-startup>
    </servlet>
    
    <servlet-mapping>
        <servlet-name></servlet-name>
        <url-pattern></url-pattern>
    </servlet-mapping>
    
    <filter>
        <filter-name></filter-name>
        <filter-class></filter-class>
        <init-param>
            <param-name></param-name>
            <param-value></param-value>
        </init-param>
    </filter>
    
    <filter-mapping>
        <filter-name></filter-name>
        <url-pattern></url-pattern>
    </filter-mapping>
    
    <welcome-file-list>
        <welcome-file></welcome-file>
    </welcome-file-list>
</web-app>