package devmanuals; import javax.servlet.*; import java.io.*; public class GetCntx extends GenericServlet { ServletContext ctx; String url; public void init(ServletConfig cfig) { // Obtain the ServletContext object ctx = cfig.getServletContext(); } public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { // Retrieve the URL attribute url = (String) ctx.getAttribute("URL"); // Obtain a PrintWriter object PrintWriter pw = response.getWriter(); // Send response to display the value of the URL attribute response.setContentType("text/html"); pw.println("The URL value is : " + url + "
"); } }