Servlet(五岁以下儿童)web.xml一些常用的配置

(1)lode-on-startup,这Servlet该项目启动时它将被称为(从主要的电话init办法,为了安全起见,一般不应为Servlet建立URL制图)。一些数据通常被用作前处理,或使用多线程建立经常性的任务

    <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 表示多个预处理Servlet的启动顺序--> <lode-on-startup>1</lode-on-startup> </servlet>



(2)init-param,可用做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>

能够在FirstServlet的do*方法中使用this.getServletConfig().getInitParameter("encoding");获取web.xml中encoding值utf-8

    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>

能够在FirstServlet的do*方法中

  

Enumeration<String> names = this.getServletConfig().getInitParameterNames();
      while(names.hasMoreElements()){
      	//name为每一个init-param名字
      	String name=names.nextElement();
      }
(3)context-param。全局配置信息。可在多个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>
        <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>

能够在*Servlet的do*方法中使用String date = this.getServletContext().getInitParameter("date");获取最新  

版权声明:本文博主原创文章,博客,未经同意不得转载。

posted @ 2015-10-25 12:19  phlsheji  阅读(180)  评论(0编辑  收藏  举报