Servlets (children under five) Web. XML some common configurations

Source: Internet
Author: User

(1) Lode-on-startup, this servlet when the project is started it will be called (from the main phone init method, for security reasons, the servlet should not generally establish a URL mapping). Some data is often used as a pre-processing or use multithreading to build recurring 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>

Ability to 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 used in the do* method of Firstservlet

enumeration<string> names = This.getservletconfig (). Getinitparameternames ();      while (Names.hasmoreelements ()) {      //name is a      String name=names.nextelement () for each init-param name;      }
(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>

The ability to use string date = This.getservletcontext () in the do* method of *servlet. Getinitparameter ("date"); get the latest

Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

Servlets (children under five) Web. XML some common configurations

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.