This J2EE tip describes a method of handling servletcontext initialization parameter. Context initialization parameters may be used as the basis of data that is made available to all servlets and JSP pages. Each web application consists of one ServletContext, which can be used as share resources (data stored in ServletContext)

import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class ContextInitParameters extends HttpServlet {
  ServletConfig config ;
  public void init(ServletConfig config)throws ServletException {
    this.config = config;

  public void doGet(HttpServletRequest request, HttpServletResponse response
    throws ServletException , IOException {
    try {
      PrintWriter out = response.getWriter();
      ServletContext application = config.getServletContext();
      String driverclass = 
      String jdbcURL = application.getInitParameter("jdbcURL")
      String user = application.getInitParameter("user")
      String password = application.getInitParameter("pass")
      Connection con = DriverManager.getConnection(jdbcURL);
      String query = "insert into dept values(50,'Developing','India')";
      Statement stmt = con.createStatement();
      int i = stmt.executeUpdate(query);
      if(i==0) {
        out.println("Not Inserted");
      else {
        out.println("Values Inserted");
    catch (Exception e) {

Here is the web.xml for the servlet. Here one context-param can hold only one value: