1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| import javax.servlet.*;
import java.io.*;
public class SetttingCntx extends GenericServlet
{
ServletContext ctx;
public void init (ServletConfig cfig)
{
/*Obtain the ServletContext object */
ctx=cfig.getServletContext();
}
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException
{
/* set the context attribute*/
ctx.setAttribute("URL","jdbc:odbc:EmployeesDB");
/*obtain the PrintWriter object*/
PrintWriter pw=response.getWriter();
/* Send response to indicate that the URL attribute as been set*/
response.setContentType("text/html");
pw.println("<B>The JDBC URL has been set as a context attribute</B>");
}
} |
Partager