Init Param Servlet : Web INF XML « Servlets « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JDK 6
25.JNDI LDAP
26.JPA
27.JSP
28.JSTL
29.Language Basics
30.Network Protocol
31.PDF RTF
32.Reflection
33.Regular Expressions
34.Scripting
35.Security
36.Servlets
37.Spring
38.Swing Components
39.Swing JFC
40.SWT JFace Eclipse
41.Threads
42.Tiny Application
43.Velocity
44.Web Services SOA
45.XML
Java Tutorial
Java Book
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
SCJP
Java » Servlets » Web INF XMLScreenshots 
Init Param Servlet
  

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.PrintWriter;
import java.io.IOException;

public class InitParamServlet extends HttpServlet 
{
  public void doGet(HttpServletRequest req, HttpServletResponse resthrows IOException, ServletException 
  {

    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();

    String url = getInitParameter("URL");

    ServletConfig config = getServletConfig();
    ServletContext context = getServletContext();
    String uid = config.getInitParameter("UID");
    String pwd = config.getInitParameter("PWD");
    String port = context.getInitParameter("some-port");

    out.println("Values retrieved for the init parameters are: ");
    out.println("URL: " + url);
    out.println("UID: " + uid);
    out.println("PWD: " + pwd);
    out.println("some-port: " + port);
  }
}

           
         
    
  
ServletParameter.zip( 89 k)
Related examples in the same category
1.Using Initialization Parameters Servlet
2.Servlet Mapping In Web XML
3.A WebAppConfig object is a wrapper around a DOM tree for a web.xml file
4.Define welcome files for web application
5.Parse a web.xml file using the SAX2 API
6.War Util
ww__w_.j_a_v__a2__s.c_o_m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.