KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > example > MovieServlet


1 package example;
2
3 import java.io.PrintWriter JavaDoc;
4 import java.io.IOException JavaDoc;
5
6 import javax.servlet.ServletException JavaDoc;
7
8 import javax.servlet.http.HttpServletRequest JavaDoc;
9 import javax.servlet.http.HttpServletResponse JavaDoc;
10 import javax.servlet.http.HttpServlet JavaDoc;
11
12 public class MovieServlet extends HttpServlet JavaDoc {
13   private MovieLister _movieLister;
14
15   /**
16    * Sets the movie lister.
17    */

18   public void setMovieLister(MovieLister lister)
19   {
20     _movieLister = lister;
21   }
22   
23   /**
24    * Returns movies by a particular director.
25    */

26   public void doGet(HttpServletRequest JavaDoc request,
27             HttpServletResponse JavaDoc response)
28     throws IOException JavaDoc, ServletException JavaDoc
29   {
30     PrintWriter JavaDoc out = response.getWriter();
31
32     response.setContentType("text/html");
33
34     String JavaDoc director = request.getParameter("director");
35
36     if (director == null) {
37       out.println("No director specified");
38       return;
39     }
40
41     out.println("<h1>Director: " + director + "</h1>");
42
43     Movie []movies = _movieLister.moviesDirectedBy(director);
44
45     for (int i = 0; i < movies.length; i++)
46       out.println(movies[i].getTitle() + "<br>");
47   }
48 }
49
Popular Tags