KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > FooAction


1 import java.io.*;
2 import javax.servlet.*;
3 import javax.servlet.http.*;
4
5 import jodd.servlet.*;
6
7 public class FooAction extends ActionServlet {
8
9     /**
10      * Main entry point for handling fooaction requests. This ActionServlet
11      * is used as enhancement of the HttpServlet.
12      *
13      * @param request
14      * @param response
15      *
16      * @exception IOException
17      * @exception ServletException
18      */

19     public void doRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
20         System.out.println("---------------------");
21         System.out.println("FooAction.doRequest()");
22
23         // invoke action specified by request parameter 'action'
24
String s = invokeAction(request, response);
25         System.out.println("invoking result: " + s);
26         if (s != null) {
27             return; // invoking was sucessfull
28
}
29
30         // no action (method) has been invoked, try to use
31
// forward or redirect params anyway, if they exist
32
if (forwardParam(request, response)) return;
33         if (redirectParam(request, response)) return;
34         
35         // none of the three parameters (action, forward, redirect) has been specified
36
// do the default behaviour
37
System.out.println("nothing to do, just go back...");
38         redirect(request, response, "index.html");
39     }
40
41     /**
42      * The first http request handler (i.e. action). The important thing to
43      * remember is that this method may return anything, any kind of object, it
44      * will be converted to String representation. For the example, if boolean
45      * value of true is returned (as here), doRequest() will got the String with
46      * value "true". This may be useful for noticing if some action method
47      * actually has been invoked, so doRequest can return back.
48      *
49      * @param request
50      * @param response
51      *
52      * @return
53      * @exception IOException
54      * @exception ServletException
55      */

56     public boolean one(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
57         System.out.println(">ACTION #1");
58         return true;
59     }
60
61     public boolean two(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
62         System.out.println(">ACTION #2, redirect");
63         redirectParam(request, response);
64         return true;
65     }
66
67     public boolean three(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
68         System.out.println(">ACTION #3, forward");
69         forwardParam(request, response);
70         return true;
71     }
72
73
74 }
75
76
Popular Tags