01: package org.nanocontainer.webcontainer;
02:
03: import java.io.IOException;
04:
05: import javax.servlet.ServletConfig;
06: import javax.servlet.ServletException;
07: import javax.servlet.http.HttpServlet;
08: import javax.servlet.http.HttpServletRequest;
09: 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)
20: throws ServletException {
21: String initParameter = servletConfig.getInitParameter("foo");
22: if (initParameter != null) {
23: foo = initParameter;
24: }
25: }
26:
27: protected void doGet(HttpServletRequest request,
28: HttpServletResponse response) throws ServletException,
29: IOException {
30: response.setContentType("text/plain");
31: String message = name;
32: if (request.getAttribute("foo2") != null) {
33: message = message + request.getAttribute("foo2");
34: }
35:
36: String text = "hello " + message
37: + (foo != null ? " " + foo : "");
38: response.getWriter().write(text);
39: }
40:
41: public void destroy() {
42: }
43:
44: // used when handling this servlet directly rather than letting Jetty instantiate it.
45: public void setFoo(String foo) {
46: this.foo = foo;
47: }
48: }
|