01: package test;
02:
03: import java.io.*;
04:
05: import javax.servlet.http.*;
06: import javax.servlet.*;
07:
08: /**
09: * Bean-style initialization servlet. The greeting parameter is configured
10: * in the <init> section of the <servlet>. The <code>setXXX</code>
11: * methods are called before the <code>init()</code> method.
12: *
13: * <code><pre>
14: * <servlet servlet-name='hello'
15: * servlet-class='test.HelloServlet'>
16: * <init>
17: * <greeting>Hello, world</greeting>
18: * </init>
19: * </servlet>
20: * </pre></code>
21: */
22: public class HelloServlet extends HttpServlet {
23: private String _greeting = "Default Greeting";
24:
25: /**
26: * Sets the greeting.
27: */
28: public void setGreeting(String greeting) {
29: _greeting = greeting;
30: }
31:
32: /**
33: * Returns the greeting.
34: */
35: public String getGreeting() {
36: return _greeting;
37: }
38:
39: /**
40: * Implements the HTTP GET method. The GET method is the standard
41: * browser method.
42: *
43: * @param request the request object, containing data from the browser
44: * @param repsonse the response object to send data to the browser
45: */
46: public void doGet(HttpServletRequest request,
47: HttpServletResponse response) throws ServletException,
48: IOException {
49: // Returns a writer to write to the browser
50: PrintWriter out = response.getWriter();
51:
52: // Writes the string to the browser.
53: out.println(_greeting);
54: out.close();
55: }
56: }
|