KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > madvoc > result > ServletDispatcherResult


1 // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
2

3 package jodd.madvoc.result;
4
5 import jodd.madvoc.ActionRequest;
6 import jodd.servlet.DispatcherUtil;
7
8 import javax.servlet.RequestDispatcher JavaDoc;
9 import javax.servlet.http.HttpServletRequest JavaDoc;
10 import javax.servlet.http.HttpServletResponse JavaDoc;
11
12 /**
13  * Dispatches to a JSP page.
14  *
15  * @see ServletForwardResult
16  */

17 public class ServletDispatcherResult extends ActionResult {
18
19     protected static String JavaDoc EXTENSION = ".jsp";
20     public static final String JavaDoc NAME = "dispatch";
21
22     public ServletDispatcherResult() {
23         super(NAME);
24     }
25
26     /**
27      * Dispatches to the given location. Does its forward via a RequestDispatcher. If the
28      * dispatch fails a 404 error will be sent back in the http response.
29      */

30     public void execute(ActionRequest actionRequest, String JavaDoc resultValue) throws Exception JavaDoc {
31         HttpServletRequest JavaDoc request = actionRequest.getHttpServletRequest();
32         HttpServletResponse JavaDoc response = actionRequest.getHttpServletResponse();
33         String JavaDoc target = resultValue + EXTENSION;
34
35         RequestDispatcher JavaDoc dispatcher = request.getRequestDispatcher(target);
36         if (dispatcher == null) {
37             response.sendError(404, "Result '" + target + "' not found");
38             return;
39         }
40
41         // If we're included, then include the view, otherwise do forward.
42
// This allow the page to, for example, set content type.
43
if (DispatcherUtil.isPageIncluded(request, response)) {
44             dispatcher.include(request, response);
45         } else {
46             dispatcher.forward(request, response);
47         }
48     }
49
50 }
51
Popular Tags