package devmanuals; import javax.servlet.*; import java.io.*; public class SetContext 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 has been set response.setContentType("text/html"); pw.println("The JDBC URL has been set as a context attribute"); } }