Enterprise Beans

Contact Us

Implementing Context Initialization Parameter


Example for Implementing Context Initialization Parameter

CLICK HERE to download this complete example (zip file)

 Create a servlet

import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class InitParameterDemo extends HttpServlet
    String strName;
    String strValue;
    Enumeration enu;
    public void init() throws ServletException
       ServletContext ctx = getServletContext();
          enu = ctx.getInitParameterNames();
          while (enu.hasMoreElements())
             strName = (String)enu.nextElement();
             strValue = ctx.getInitParameter(strName);
       catch(Exception e)
    public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
       PrintWriter out = res.getWriter();
       out.println("Please post your valuable feedback and suggestions to: "+strValue );


 Specify the initialization parameters
  1. Write a java program and name it as
  2. Set the path in the command prompt
    set path=.;C:\progra~1\java\j2sdk1.5.0\bin;C:\Sun\AppServer\bin;
    Set classpath=.;C:\progra~1\java\j2sdk1.5.0\lib;C:\Sun\AppServer\lib\j2ee.jar;
    Set the path in the system itself. CLICK HERE for details
  3. Now compile the CLICK HERE to see how to compile
  4. Goto Start->Programs->Sun Microsystems->Application Server PE->Start Default Server (Wait till it start and then press any key). CLICK HERE to see how to Start the Server
  5. Goto Start->Programs-> Sun Microsystems->Application Server PE->Deploytool. CLICK HERE to see how to Start the Deploytool
  6. Goto File ->New -> Application     Note:    Inserted of EmployeeDetails use InitParameterDemo

    (Click the Browse button)

  7. (Select the folder in the Look In dropdown box, and then give a file name “InitParameterDemo”. Next click the New Application button)

  8. (Click the OK button)
  9. Now goto File -> Save to save the file
  10. Next, goto File -> New -> Web Component

    (Click Next button)

  11. (Enter the WAR Name as “EmpApp” and then click the Edit Contents… button)

  12. (Select all the .class, .jsp , .tld and .html files and click the Add button)

  13. (Now click the OK button)

  14. (Now click the Next button)

  15. (Now select the Servlet option button and then click the Next button)

  16. (Now select the “InitParameterDemo” from the Servlet Class dropdown box)

  17. (Now select the Next button)

  18. (Now select the Finish button)

  19. (Now select the EmpApp in the left pane and select the General tab in the right pane. Here give a name “example2” in the Context Root text box)
  20. Next select the InitParameterDemo in the right side

    (Now select the InitParameterDemo in the left pane and then select the Aliases tab in the right pane. Next select the Add button)

  21. (Now add a name as “InitParameterDemo”)

  22. Now select WebApp in the left pan and then select the context tab in the right pane
  23. Click the Add button to add a new row in the Context Parameters Referenced in Code pane
  24. Type the name of the Coded Parameter as email_id and the value as in the value column
  25. Select the File->Save command to save the web module
  26. Select the InitParameterDemo in the right pane
  27. Now goto File ->Save
  28. Next goto Tools -> Deployee

    (Enter the User Name as “admin” and Password as “password” (CLICK HERE for password). Next click the OK button)

  29. (Now a message --- Operation Completed Successfully --- must display. Next click the Close button)
  30. Next goto File -> Exit to close it
  31. Now open an Internet Explorer and type the address http:// localhost:8080/example2/InitParameterDemo

  32. Program completed Successfully
  33. To stop the server goto Start -> All Programs -> Sun Microsystems -> Application Server PE -> Stop Default Server. CLICK HERE to see how to Stop the Server

 Click for Next Topic