01: package simpleorm.simplehtml;
02:
03: import java.io.IOException;
04: import javax.servlet.ServletException;
05: import javax.servlet.http.HttpServlet;
06: import javax.servlet.http.HttpServletRequest;
07: import javax.servlet.http.HttpServletResponse;
08:
09: /**
10: * The master servelt that dispatches to each of the Requestlets.
11: *
12: * $Id: HMasterServlet.java,v 1.4 2006/04/18 06:25:54 aberglas Exp $
13: * @author aberglas
14: */
15: public class HMasterServlet extends HttpServlet {
16:
17: void doGetPost(HttpServletRequest req, HttpServletResponse res,
18: boolean isGet) {
19: String uri = req.getRequestURI(); // includes the context, but not anything after the ?
20: //int rx = uri.lastIndexOf('/');
21: //String rname = uri.substring(rx+1);
22: HSuperRequestlet prototype = HSuperRequestlet.registry.get(uri);
23: if (prototype == null)
24: throw new RuntimeException("No Requestlet found for URL "
25: + uri);
26: HSuperRequestlet rlet = null;
27: try {
28: rlet = prototype.getClass().newInstance();
29: } catch (Exception ex) {
30: throw new RuntimeException(ex);
31: }
32:
33: rlet.initRequestlet(this , req, res, isGet);
34: rlet.doGetPost();
35: }
36:
37: protected void doGet(HttpServletRequest req, HttpServletResponse res)
38: throws ServletException, IOException {
39: doGetPost(req, res, true);
40: }
41:
42: protected void doPost(HttpServletRequest req,
43: HttpServletResponse res) throws ServletException,
44: IOException {
45: doGetPost(req, res, false);
46: }
47: }
|