How to configure Servlet information in the .xml file .xml information on how to configure the Servlet

How to configure Servlet information in the .xml

 

Servlet needs to be configured in the web.xml file after file written your servlet, the servlet to run on the server. The basic configuration is as follows

 

Copy the code
<context-param>
    <param-name>context1</param-name>
    <param-value>000001</param-value>
</context-param>
<context-param>
    <param-name>context2</param-name>
    <param-value>000002</param-value>
</context-param>
<servlet>
    <servlet-name>helloServlet</servlet-name>
    <servlet-class>com.hamigua.servlet.HelloServlet</servlet-class>
    <init-param>
        <param-name>User</param-name>
        <param-value>Servlet1</param-value>
    </init-param>
    <init-param>
        <param-name>PassWord</param-name>
        <param-value>123456</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>helloServlet</servlet-name>
    <url-pattern>/testServlet</url-pattern>
</servlet-mapping>
Copy the code

 

Here there are two main blocks <servlet> configuration, and <servlet-mapping> mapping.

Wherein, <context-param> are provided servlet initialization parameters (global, all servlet can be used), to create ServletContext object by object ServletConfig the init () method, by calling the object ServletContext getInitParameter ( "User ") method to get the value corresponding to the value of the User, call getInitParameterNames () method to get the value of all the name calling getRealPath () Gets absolute path to a file on the server, call getContextPath () Gets the name of the current web application project .

   <Servlet-name> is a unique name for this configuration since the .xml file, this file can not be other configurations with the same name. While <servlet-mapping> in <servlet-name> must match the name of this, it is the same as a servlet configuration.

   <Servlet-class> is the fully qualified name of the servlet class file is located.

   <Init-param> and <context-param> as setting some of the servlet initialization parameters (partial limited servlet) () method call in object uses ServletConfig getInitParameter ( "User") acquired in the init method corresponding to User the value argument, calling getInitParameterNames () method to get all the name value.

   <Load-on-startup> servlet is created, timing, i.e. init () method call time, if the value is a natural number smaller the first to be created.

   <Url-pattern> is a path to access the external servlet, starting from the root directory, / testServlet TestServlet represents the root directory. / * Represents all files accessible to the root directory of this servlet, *. Jsp jsp suffix means all the servlet can access this file in the root directory.

Transfer: https://www.cnblogs.com/hamihua/p/6690676.html

Servlet needs to be configured in the web.xml file after file written your servlet, the servlet to run on the server. The basic configuration is as follows

 

Copy the code
<context-param>
    <param-name>context1</param-name>
    <param-value>000001</param-value>
</context-param>
<context-param>
    <param-name>context2</param-name>
    <param-value>000002</param-value>
</context-param>
<servlet>
    <servlet-name>helloServlet</servlet-name>
    <servlet-class>com.hamigua.servlet.HelloServlet</servlet-class>
    <init-param>
        <param-name>User</param-name>
        <param-value>Servlet1</param-value>
    </init-param>
    <init-param>
        <param-name>PassWord</param-name>
        <param-value>123456</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>helloServlet</servlet-name>
    <url-pattern>/testServlet</url-pattern>
</servlet-mapping>
Copy the code

 

Here there are two main blocks <servlet> configuration, and <servlet-mapping> mapping.

Wherein, <context-param> are provided servlet initialization parameters (global, all servlet can be used), to create ServletContext object by object ServletConfig the init () method, by calling the object ServletContext getInitParameter ( "User ") method to get the value corresponding to the value of the User, call getInitParameterNames () method to get the value of all the name calling getRealPath () Gets absolute path to a file on the server, call getContextPath () Gets the name of the current web application project .

   <Servlet-name> is a unique name for this configuration since the .xml file, this file can not be other configurations with the same name. While <servlet-mapping> in <servlet-name> must match the name of this, it is the same as a servlet configuration.

   <Servlet-class> is the fully qualified name of the servlet class file is located.

   <Init-param> and <context-param> as setting some of the servlet initialization parameters (partial limited servlet) () method call in object uses ServletConfig getInitParameter ( "User") acquired in the init method corresponding to User the value argument, calling getInitParameterNames () method to get all the name value.

   <Load-on-startup> servlet is created, timing, i.e. init () method call time, if the value is a natural number smaller the first to be created.

   <Url-pattern> is a path to access the external servlet, starting from the root directory, / testServlet TestServlet represents the root directory. / * Represents all files accessible to the root directory of this servlet, *. Jsp jsp suffix means all the servlet can access this file in the root directory.

Transfer: https://www.cnblogs.com/hamihua/p/6690676.html

Guess you like

Origin www.cnblogs.com/kyrie211/p/10990767.html