Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


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


How set Init Parameter in servlet ?


Advertisement
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 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>
Access web.xml init parameters
Access web.xml init parameters  How to access web.xml init parameters from java code
Servlet Init method
Servlet Init method  can we capture the form data into the init method of the servlet
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
validate parameter before using it
validate parameter before using it   How to validate the parameter before using it in JSP
Java parameter passing
Java parameter passing  What type of parameter passing does Java support
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
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
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 a parameter using URL string
Passing a parameter using URL string  How to pass a parameter using the URL string in a JSF application
Passing Parameter - JSP-Servlet
, there's var answer. I need to pass this parameter back into the jsp part, how should i do
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
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
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
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
 

 

 

DMCA.com