Init Parameter

Init Parameter

How set Init Parameter in servlet ?

View Answers

November 17, 2010 at 12:00 PM

Init parameters are set in the web.xml and access in the servlet class . Init parameter are set in the web.xml as :

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
 PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
<servlet>

 <init-param>
   <param-name>Email</param-name>
   <param-value>[email protected]</param-value>
 </init-param>
 <init-param>
  <param-name>Address</param-name>
  <param-value>Dehli</param-value>
 </init-param> 

  <servlet-name>InitParameter</servlet-name>
  <servlet-class>InitServlet</servlet-class>
 </servlet>

 <servlet-mapping>
  <servlet-name>InitParameter</servlet-name>
  <url-pattern>/InitServlet</url-pattern>
 </servlet-mapping>

</web-app>

Again access parameter in the servlet as :

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;

public class InitServlet extends HttpServlet {
  public void doGet(HttpServletRequest request, HttpServletResponse response)
                                  throws ServletException, IOException {
    PrintWriter pw = response.getWriter();
    pw.print("Init Parameters are : ");
    Enumeration enumeration = getServletConfig().getInitParameterNames();        
    pw.println("\nThe Email : " + getServletConfig().getInitParameter("Email"));
    pw.println("The address : " + getServletConfig().getInitParameter("Address"));       
  }
}









Related Tutorials/Questions & Answers:
Init Parameter
Init Parameter  How set Init Parameter in servlet
Getting Init Parameter Names
Getting Init Parameter Names       In this example we are going to retreive the init paramater... the content on the browser. To retrieve all the values of the init parameter use
Advertisements
Counter in Init() Method
and by reading the init parameter to know from where the counting will begin. In this program we are going to make use of the init method of the Servlet interface...: #000000; } Counter in Init() Method     
init method
init method  why init method used in servlet?   The init() method is called only once by the servlet container throughout the life of a servlet. By this init() method the servlet get to know that it has been placed
difference between init() & init(ServletConfig config)?
difference between init() & init(ServletConfig config)?  I want to know the difference between init() and init(ServletConfig config) methods in GenericServlet
Init param - Java Beginners
the parameter values.public void init(ServletConfig config) throws ServletException...Init param  What is the correct syntax of init param?  Hello,Init parameters are added between the <init-param></init-param>
Java parameter passing
Java parameter passing  What type of parameter passing does Java support
validate parameter before using it
validate parameter before using it   How to validate the parameter before using it in JSP
ModuleNotFoundError: No module named 'parameter'
ModuleNotFoundError: No module named 'parameter'  Hi, My Python... 'parameter' How to remove the ModuleNotFoundError: No module named 'parameter' error? Thanks   Hi, In your python environment you
Servlet Init method
Servlet Init method  can we capture the form data into the init method of the servlet
Access web.xml init parameters
Access web.xml init parameters  How to access web.xml init parameters from java code
ModuleNotFoundError: No module named 'init'
ModuleNotFoundError: No module named 'init'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'init' How to remove the ModuleNotFoundError: No module named 'init' error
init method of ActionServlet and RequestProcessor
init method of ActionServlet and RequestProcessor  hi every when the ActionServlet init() method is executed? please give answer for the above query
Version of cn.zhaiyifan>init dependency
List of Version of cn.zhaiyifan>init dependency
pass parameter names and values
pass parameter names and values  What is the <jsp:param> standard action?   The <jsp:param> standard action is used with <jsp:include> or <jsp:forward> to pass parameter names and values
optional parameter of Test annotattion
optional parameter of Test annotattion   What are two optional parameters of @Test annotation ?   The Test annotation supports two optional... parameter, timeout, causes a test to fail if it takes longer than a specified amount
SQL Out Parameter
SQL Out Parameter       SQL Out Parameter allows the stored procedure to the pass data value ... illustrate an example from SQL Out Parameter .In this Example we create a procedure
Passing a parameter using URL string
Passing a parameter using URL string  How to pass a parameter using the URL string in a JSF application
optional parameter of Test annotattion
optional parameter of Test annotattion   The Test annotation supports two optional parameters. The first, expected, declares that a test method should throw an exception. If it doesn't throw an exception or if it throws
Passing Parameter - JSP-Servlet
Passing Parameter  I would like to ask how to pass a parameter from javascript section into the jsp section.It will be something like this: function change() { var answer = document.getElementById('selc').value
parameter meta data - JDBC
parameter meta data   i wnts to know about the finition of parameter in jdbc as well as the diffrent methods used in parameter meta data  Hi friend, public interface ResultSetMetaData An object that can be used
ModuleNotFoundError: No module named 'lib-parameter'
ModuleNotFoundError: No module named 'lib-parameter'  Hi, My... 'lib-parameter' How to remove the ModuleNotFoundError: No module named 'lib-parameter' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'magic_parameter'
ModuleNotFoundError: No module named 'magic_parameter'  Hi, My... named 'magic_parameter' How to remove the ModuleNotFoundError: No module named 'magic_parameter' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'parameter-sherpa'
ModuleNotFoundError: No module named 'parameter-sherpa'  Hi, My... named 'parameter-sherpa' How to remove the ModuleNotFoundError: No module named 'parameter-sherpa' error? Thanks   Hi, In your
Passing Parameter - JSP-Servlet
, there's var answer. I need to pass this parameter back into the jsp part, how should i do
Parameter Tag:
Parameter Tag:       bean:parameter...) of the specified request parameter. This tag retrieve the value of the specified request parameter and define the attribute of  type String or String[] in page scope
Objective-C program with multiple parameter
Objective-C program with multiple parameter  ... with multiple parameter. These parameter can be of same type or of different...:NSObject{ } // declare method for more than one parameter -(int) sum
Version of com.laamella>parameter-source dependency
List of Version of com.laamella>parameter-source dependency
PHP add parameter to url - PHP
PHP add parameter to url  need an example of parse_url in PHP. Thanks in advance
ModuleNotFoundError: No module named 'dev-init'
ModuleNotFoundError: No module named 'dev-init'  Hi, My Python...-init' How to remove the ModuleNotFoundError: No module named 'dev-init... to install padas library. You can install dev-init python with following
ModuleNotFoundError: No module named 'mine-init'
ModuleNotFoundError: No module named 'mine-init'  Hi, My Python... 'mine-init' How to remove the ModuleNotFoundError: No module named 'mine-init' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'mine-init'
ModuleNotFoundError: No module named 'mine-init'  Hi, My Python... 'mine-init' How to remove the ModuleNotFoundError: No module named 'mine-init' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'npg-init'
ModuleNotFoundError: No module named 'npg-init'  Hi, My Python...-init' How to remove the ModuleNotFoundError: No module named 'npg-init... to install padas library. You can install npg-init python with following
ModuleNotFoundError: No module named 'pcart-init'
ModuleNotFoundError: No module named 'pcart-init'  Hi, My Python... 'pcart-init' How to remove the ModuleNotFoundError: No module named 'pcart-init' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'pip-init'
ModuleNotFoundError: No module named 'pip-init'  Hi, My Python...-init' How to remove the ModuleNotFoundError: No module named 'pip-init... to install padas library. You can install pip-init python with following
ModuleNotFoundError: No module named 'pkg-init'
ModuleNotFoundError: No module named 'pkg-init'  Hi, My Python...-init' How to remove the ModuleNotFoundError: No module named 'pkg-init... to install padas library. You can install pkg-init python with following
ModuleNotFoundError: No module named 'pyb_init'
ModuleNotFoundError: No module named 'pyb_init'  Hi, My Python..._init' How to remove the ModuleNotFoundError: No module named 'pyb_init... to install padas library. You can install pyb_init python with following
ModuleNotFoundError: No module named 'py-init'
ModuleNotFoundError: No module named 'py-init'  Hi, My Python...-init' How to remove the ModuleNotFoundError: No module named 'py-init... to install padas library. You can install py-init python with following command
ModuleNotFoundError: No module named 'pymod-init'
ModuleNotFoundError: No module named 'pymod-init'  Hi, My Python... 'pymod-init' How to remove the ModuleNotFoundError: No module named 'pymod-init' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'qingcloud-init'
ModuleNotFoundError: No module named 'qingcloud-init'  Hi, My... named 'qingcloud-init' How to remove the ModuleNotFoundError: No module named 'qingcloud-init' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'aiohttp-init'
ModuleNotFoundError: No module named 'aiohttp-init'  Hi, My Python... 'aiohttp-init' How to remove the ModuleNotFoundError: No module named 'aiohttp-init' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'apertium-init'
ModuleNotFoundError: No module named 'apertium-init'  Hi, My... 'apertium-init' How to remove the ModuleNotFoundError: No module named 'apertium-init' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'auto-init'
ModuleNotFoundError: No module named 'auto-init'  Hi, My Python... 'auto-init' How to remove the ModuleNotFoundError: No module named 'auto-init' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'cloudbase-init'
ModuleNotFoundError: No module named 'cloudbase-init'  Hi, My... named 'cloudbase-init' How to remove the ModuleNotFoundError: No module named 'cloudbase-init' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'dbt-init'
ModuleNotFoundError: No module named 'dbt-init'  Hi, My Python...-init' How to remove the ModuleNotFoundError: No module named 'dbt-init... to install padas library. You can install dbt-init python with following
ModuleNotFoundError: No module named 'dev-init'
ModuleNotFoundError: No module named 'dev-init'  Hi, My Python...-init' How to remove the ModuleNotFoundError: No module named 'dev-init... to install padas library. You can install dev-init python with following
ModuleNotFoundError: No module named 'django-init'
ModuleNotFoundError: No module named 'django-init'  Hi, My Python... 'django-init' How to remove the ModuleNotFoundError: No module named 'django-init' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'dumb-init'
ModuleNotFoundError: No module named 'dumb-init'  Hi, My Python... 'dumb-init' How to remove the ModuleNotFoundError: No module named 'dumb-init' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'easy-init'
ModuleNotFoundError: No module named 'easy-init'  Hi, My Python... 'easy-init' How to remove the ModuleNotFoundError: No module named 'easy-init' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'Flask-Init'
ModuleNotFoundError: No module named 'Flask-Init'  Hi, My Python... 'Flask-Init' How to remove the ModuleNotFoundError: No module named 'Flask-Init' error? Thanks   Hi, In your python environment you

Ads