01: package example;
02:
03: import java.io.PrintWriter;
04: import java.io.IOException;
05:
06: import javax.servlet.ServletException;
07:
08: import javax.servlet.http.HttpServletRequest;
09: import javax.servlet.http.HttpServletResponse;
10: import javax.servlet.http.HttpServlet;
11:
12: import javax.webbeans.In;
13:
14: public class MovieServlet extends HttpServlet {
15: // Inject the MovieLister service
16: @In
17: private MovieLister _movieLister;
18:
19: /**
20: * Returns movies by a particular director.
21: */
22: public void doGet(HttpServletRequest request,
23: HttpServletResponse response) throws IOException,
24: ServletException {
25: PrintWriter out = response.getWriter();
26:
27: response.setContentType("text/html");
28:
29: String director = request.getParameter("director");
30:
31: if (director == null) {
32: out.println("No director specified");
33: return;
34: }
35:
36: out.println("<h1>Director: " + director + "</h1>");
37:
38: for (Movie movie : _movieLister.moviesDirectedBy(director)) {
39: out.println(movie.getTitle() + "<br>");
40: }
41: }
42: }
|