// web.xml
/*
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
name
Joe
password
password
ParameterServlet
ParameterServlet
name
Joe
password
password
*/
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ParameterServlet extends HttpServlet {
private String dbName = "";
private String dbPassword = "";
public void init(ServletConfig config) throws ServletException {
super.init(config);
ServletContext context = getServletContext();
dbName = context.getInitParameter("name");
dbPassword = context.getInitParameter("password");
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException {
ServletOutputStream out = res.getOutputStream();
res.setContentType("text/html");
out.println("Basic Servlet ");
out.println("Database username is " + dbName);
out.println("
Database password is " + dbPassword + "");
out.println("");
}
}