1 package example; 2 3 import java.io.PrintWriter ; 4 import java.io.IOException ; 5 6 import javax.servlet.ServletRequest ; 7 import javax.servlet.ServletResponse ; 8 import javax.servlet.GenericServlet ; 9 import javax.servlet.ServletException ; 10 11 15 public class GreetingClientServlet extends GenericServlet { 16 private String _name = "generic"; 17 private GreetingAPI _greeting; 18 19 22 public void setName(String name) 23 { 24 _name = name; 25 } 26 27 30 public void setGreeting(GreetingAPI greeting) 31 { 32 _greeting = greeting; 33 } 34 35 38 public void init() 39 throws ServletException 40 { 41 if (_greeting == null) 42 throw new ServletException ("GreetingClientServlet needs a configured greeting"); 43 } 44 45 48 public void service(ServletRequest req, ServletResponse res) 49 throws IOException , ServletException 50 { 51 PrintWriter out = res.getWriter(); 52 53 out.println(_name + ": " + _greeting.greeting()); 54 } 55 } 56 | Popular Tags |