Init Param Servlet : Web INF XML « Servlets « Java






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 res) throws 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