servlet in the web.xml configuration file parameters in context-param and the init-param District

web.xml which can be defined two parameters:
(1) application within the parameters stored in servletcontext, in web.xml, configured as follows: <context-param>
<param-name> context / param </ param-name>
<param-value> avalible during application </ param-value>
</ Context-param>
(2) servlet context parameters, only the servlet's init () method to obtain, configure in web.xml as follows:

<servlet>
<servlet-name> MainServlet </ servlet-name>
<servlet-class> com.wes.controller.MainServlet </ servlet-class>
<init-param>
<param-name> param1 </ param-name>
<param-value> avalible in servlet init () </ param-value>
</ Init-param>
<load-on-startup> 0 </ load-on-startup>
</ Servlet>
In the servlet can access through the code are:

package com.wes.controller;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

public class MainServlet extends HttpServlet (

public MainServlet () (
super ();
)
public void init () throws ServletException (
System.out.println ("The following two parameters param1 is stored in the servlet's");
System.out.println (this.getInitParameter ("param1"));
System.out.println ("The following parameters are stored in servletcontext in");
System.out.println (getServletContext (). GetInitParameter ("context / param"));
)
)

The first parameter in the servlet which can getServletContext (). GetInitParameter ("context / param") can only be the second parameter servlet's init () method by this.getInitParameter ("param1") to take

分类:Java 时间:2010-06-17 人气:178
分享到:
blog comments powered by Disqus

相关文章

  • Java Properties file to read the six methods 2010-07-08

    Properties file using the J2SE API to read the six methods 1. Using the java.util.Properties class load () method example: InputStream in = lnew BufferedInputStream (new FileInputStream (name)); Properties p = new Properties (); p.load (in); 2. Use j

  • Java properties file to read [transfer] 2010-12-29

    Java properties file to read] [switch Use J2SE API methods to read documents in the six Properties 1. Using the java.util.Properties class load () method example: InputStream in = lnew BufferedInputStream (new FileInputStream (name)); Properties p =

  • mysql configuration file load order. precedence effect parameters 2011-05-24

    mysql configuration file and the parameter file load order priority in force, from high ----------> low 1, mysql start directly specify the specific parameters 2, mysql startup configuration file directly to the specified location, priority, time 3,

  • Description of the parameters of the configuration file Redis [turn] 2011-04-26

    A recent project used Redis to do data caching, using Redis most important thing is to write the configuration file, then to understand the meaning of its various configuration parameters, order a bit today and found that some parameters do not under

  • Thread error, expert help, very grateful!!! Line waiting ..... 2010-09-13

    The realization of a regular automatic upload files to FTP function, but the thread error. TimeTask.java -------------------------------------------------- ---------- import java.util.TimerTask; public class TimeTask extends TimerTask ( ftpClient ftp

  • Learning to read xml file Java (rpm) 2010-10-17

    A. Java class package com.java.test; import org.w3c.dom .*; import javax.xml.parsers .*; import java.io. *; public class JavaReadXml { / / Document can be viewed as XML in memory of a mirror, then once you can get the Document means by / / Memory ope

  • Jxl import Excel data 2010-10-19

    Java code package com.pjb.sys.util; import java.io.File; import java.io.InputStream; import java.util.ArrayList; import jxl.Cell; import jxl.Sheet; import jxl.Workbook; import jxl.write.Label; import jxl.write.WritableSheet; import jxl.write.Writable

  • Actual testing framework STRUTSTESTCASE STRUTS 2010-01-28

    Read Abstract StrutsTestCase is a powerful easy-to-use testing framework for Struts actions. StrutsTestCase, and with the combination of traditional JUnit test will give you a very high test coverage and improve the reliability of your product. I. In

  • Xml file to read on to learn Java 2011-09-21

    One. Java class package com.java.test; import org.w3c.dom .*; import javax.xml.parsers .*; import java.io. *; public class JavaReadXml { / / Document can be viewed as XML in memory of a mirror, then once you can get the Document means by / / Memory o

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 闽ICP备15018612号

processed in 0.034 (s). 13 q(s)