1 package org.nanocontainer.webcontainer; 2 3 import java.io.IOException ; 4 5 import javax.servlet.ServletConfig ; 6 import javax.servlet.ServletException ; 7 import javax.servlet.http.HttpServlet ; 8 import javax.servlet.http.HttpServletRequest ; 9 import javax.servlet.http.HttpServletResponse ; 10 11 public class DependencyInjectionTestServlet extends HttpServlet { 12 private final String name; 13 private String foo; 14 15 public DependencyInjectionTestServlet(String name) { 16 this.name = name; 17 } 18 19 public void init(ServletConfig servletConfig) throws ServletException { 20 String initParameter = servletConfig.getInitParameter("foo"); 21 if (initParameter!= null) { 22 foo = initParameter; 23 } 24 } 25 26 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException , IOException { 27 response.setContentType("text/plain"); 28 String message = name; 29 if (request.getAttribute("foo2") != null) { 30 message = message + request.getAttribute("foo2"); 31 } 32 33 String text = "hello " + message + ( foo != null ? " "+ foo : "" ); 34 response.getWriter().write(text); 35 } 36 37 public void destroy() { 38 } 39 40 public void setFoo(String foo) { 42 this.foo = foo; 43 } 44 } | Popular Tags |