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

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>userEmail@gmail.com</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 Pages:
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
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>
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
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... method for more than one parameter -(int) sum: (int) a andb: (int) b andc:(int)c
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
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
Why servletcontainer can,t call the Init() method ?
Why servletcontainer can,t call the Init() method ?  Why servletcontainer can,t call the Init() method
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
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
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
Getting Context Parameter Names
Getting Context Parameters NamesGetting Context Parameter Names In this section... of the ServletContext to the context init parameters. The servlet and jsp which... = ""; private String pass = ""; public void init(ServletConfig config) throws
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
@WebInitParam Annotation Servlet Example
to use the init parameters in servlet 3.0 specificattion. In the older version of servlet init parameters specifications were given into the web.xml file...; Here you can give the name and value of init param using the initParams attribute
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
What values initialized inside init() in servlet - Java Interview Questions
What values initialized inside init() in servlet  What will happen inside init() in servlet. my interviewer asked servlet lifecycle. i said "once servlet is loaded in to memory init() will be called which performs servlet
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
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
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
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
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
how to maKE Jcombox editable after saveing value init.
how to maKE Jcombox editable after saveing value init.  i have one JCombobox with 2 values"y", "N".when i selecting some value from dropdown... after saveing value init
PHP add parameter to url - PHP
PHP add parameter to url  need an example of parse_url in PHP. Thanks in advance
Static Parameter
Static Parameter       In this section, we will develop a simple application to access the static parameters. We will use a JavaBean to set and get the static parameters. Each static parameter has a value
Date Class with Single String parameter constructor example
parameterized constructor. If user pass a string parameter in the date class.../mx" creationComplete="init();"> <fx:Script> <![CDATA[ public function init():void{ var nextDay:Date
passing parameter from html to applet
passing parameter from html to applet  how to pass the following from HTML to applet in Java code - font size,font style,font size?give me suitable code
how to pass the parameter in callable statement
how to pass the parameter in callable statement  calstat=conn.prepareCall("{call studentrc(?,?,?,?,?)}"); // it show error parameter value is null...=smark1,mark2=smark2,total=stotal where Regno=Regno; end;// how can i pass the parameter
JSP Session Parameter rewrite
JSP Session Parameter rewrite       In the section you will study about the session parameter... Parameter Rewrite</title> </head> <body> Last visit
pass parameter - file - Java Beginners
pass parameter - file  Hi, I want to pass paramter file to method. how it is possible. please send me example programs.   Hi Friend... immediately. file.jsp ========== File Parameter Use
Set Parameter - JSP-Interview Questions
Set Parameter  Hi, could someone please explain the process of setting parameter in the session from JSP with the help of code? Thanks!  Hi,In your JSP page use the Set Tag, and set the scope attribute
passing .properties file as a parameter to another function
passing .properties file as a parameter to another function  passing .properties file as a parameter to another function in an jsp file
passing .properties file as a parameter to another function
passing .properties file as a parameter to another function  passing .properties file as a parameter to another function in an jsp file
passing .properties file as a parameter to another function
passing .properties file as a parameter to another function  passing .properties file as a parameter to another function in an jsp file
passing .properties file as a parameter to another function
passing .properties file as a parameter to another function  passing .properties file as a parameter to another function in an jsp file
JSP get Parameter
JSP get Parameter          JSP get Parameter is used to return the value of a request parameter passed as query string and posted data which is encoded
JPA setParameter (Named Parameter)
JPA setParameter (Named Parameter)   ... API's method setParameter as a named parameter. JPA Query API's supports two... Here we are going to develop an application for using the named parameter
Date Class with multiple numeric parameter constructor
; creationComplete="init();"> <fx:Script> <![CDATA[ public function init():void{ var currdate:Date = new
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
Set Date Parameter to get specific value
Set Date Parameter to get specific value  How to set the date parameter or fetch a specific data records based on date? For example fetching the two or three months old records
Parameter month I Report - Java Beginners
Parameter month I Report  hy, I want to ask about how to make parameter in I Report, parameter is month from date. How to view data from i report use like "12/2008". Thank's  Hi friend, Plz give details

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.