1 package example; 2 3 import java.io.PrintWriter ; 4 import java.io.IOException ; 5 6 import javax.servlet.ServletException ; 7 8 import javax.servlet.http.HttpServletRequest ; 9 import javax.servlet.http.HttpServletResponse ; 10 import javax.servlet.http.HttpServlet ; 11 12 public class MovieServlet extends HttpServlet { 13 private MovieLister _movieLister; 14 15 18 public void setMovieLister(MovieLister lister) 19 { 20 _movieLister = lister; 21 } 22 23 26 public void doGet(HttpServletRequest request, 27 HttpServletResponse response) 28 throws IOException , ServletException 29 { 30 PrintWriter out = response.getWriter(); 31 32 response.setContentType("text/html"); 33 34 String 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 |