Servlet (v) Some of the common configuration of Web. xml

Source: Internet
Author: User

(1) Lode-on-startup, the servlet will be called at the start of the project (primarily called the Init method, for security sake, generally should not establish a URL mapping for the servlet), generally used as preprocessing some data, or with multithreading to establish timed tasks

    <servlet><pre name= "code" class= "HTML" ><span style= "font-family:arial, Helvetica, Sans-serif;" >               </span><span style= "FONT-FAMILY:SIMSUN;FONT-SIZE:12PX;" > <servlet-name>FirstServlet</servlet-name></span>
<servlet-class>com.hunhun.FirstServlet</servlet-class> <!--1 represents the start order of multiple preprocessed servlets--< Lode-on-startup>1</lode-on-startup> </servlet>


(2) Init-param, can be used to do some configuration information of the servlet

    <servlet>        <servlet-name>FirstServlet</servlet-name>        <servlet-class> com.hunhun.firstservlet</servlet-class>        <init-param>          <param-name>encoding</ param-name>          <param-value>utf-8</param-value>        </init-param>    </servlet>

You can use This.getservletconfig (). Getinitparameter ("encoding") in the do* method of Firstservlet; Get encoding value in Web. XML utf-8

More than 2.1 Init-param

    <servlet>        <servlet-name>FirstServlet</servlet-name>        <servlet-class> com.hunhun.firstservlet</servlet-class>        <init-param>          <param-name>encoding</ param-name>          <param-value>utf-8</param-value>        </init-param>        <init-param>          <param-name>author</param-name>          <param-value>hunhun</param-value>        </ init-param>        <init-param>          <param-name>versioon</param-name>          <param-value >1.0</param-value>        </init-param>    </servlet>

Can be in the do* method of Firstservlet

enumeration<string> names = This.getservletconfig (). Getinitparameternames ();      while (Names.hasmoreelements ()) {      //name for each init-param name      String name=names.nextelement ();      }
(3) Context-param, global configuration information, can be used in multiple servlets

    <servlet>        <servlet-name>FirstServlet</servlet-name>        <servlet-class> com.hunhun.firstservlet</servlet-class>        <init-param>          <param-name>encoding</ param-name>          <param-value>utf-8</param-value>        </init-param>        <init-param>          <param-name>author</param-name>          <param-value>hunhun</param-value>        </ init-param>        <init-param>          <param-name>versioon</param-name>          <param-value >1.0</param-value>        </init-param>    </servlet>    <context-param>          <param-name>date</param-name>          <param-value>2011-12-3 10:30:24</param-value>    </context-param>

You can use string date = This.getservletcontext () in the do* method of *servlet. Getinitparameter ("date"); Get to date

Servlet (v) Some of the common configuration of Web. xml

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.