Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  
 

Init Parameter

Ads

 
 

Share on Google+Share on Google+

Vijay Kumar
Init Parameter
1 Answer(s)      6 years and 9 months ago
Posted in : Servlet Interview Questions

How set Init Parameter in servlet ?

Ads
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"));       
  }
}

Ads









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... on the browser. To retrieve all the values of the init parameter use method
Advertisements
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
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     
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>
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
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
init Method in Spring
init Method in Spring       Calling Bean using init() method in Spring, this section describes  the way to initialize a bean through its lifecycle events using the init
Maven Dependency init >> 1.0.0
You should include the dependency code given in this page to add Maven Dependency of cn.zhaiyifan >> init version1.0.0 in your project
Maven Dependency init >> 1.0.1
You should include the dependency code given in this page to add Maven Dependency of cn.zhaiyifan >> init version1.0.1 in your project
Maven Dependency init >> 1.0.2
You should include the dependency code given in this page to add Maven Dependency of cn.zhaiyifan >> init version1.0.2 in your project
Why servletcontainer can,t call the Init() method ?
Why servletcontainer can,t call the Init() method ?  Why servletcontainer can,t call the Init() method
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
Version of com.massfords>jaxb-attr-init dependency
List of Version of com.massfords>jaxb-attr-init dependency
Version of com.massfords>jaxb-attr-init dependency
List of Version of com.massfords>jaxb-attr-init dependency
init Method in Spring
init Method in Spring       Calling Bean using init() method in Spring, this section describes  the way to initialize a bean through its lifecycle events using the init
init Method in Spring
init Method in Spring       Calling Bean using init() method in Spring, this section... the init() method .Here we have defined the property and values of  the bean
help to load information in init of application - Struts
help to load information in init of application  Thanks for ur... question related to struts2 framework I want to keep some data in init... that is in init of the application , please remember, i am using struts2
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
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
SQL Out Parameter
SQL Out Parameter       SQL Out Parameter allows the stored procedure to the pass data value ... from SQL Out Parameter .In this Example we create a procedure 'abc
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
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
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
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
Passing Parameter - JSP-Servlet
, there's var answer. I need to pass this parameter back into the jsp part, how should i do