|
From: Keith F I. <kir...@ho...> - 2001-08-02 06:26:04
|
One of the things I like best about the whole Java Servlet/JSP stuff is
the dispatcher model. I like to load up request handlers keyed by a URL
parameter, fire off the handler and get a "page" back, and then
dispatcht to that page.
something like:
from MyHandlers import *
def awake(self, trans): # evoked once per load into appserver?
self.commands = {}
self.commands["home"] = MyHandlers.Home()
self.commands["add"] = MyHandlers.AddItem()
..... (and many more)
def respond(self, trans):
request = trans.request()
cmd = request.field('cmd')
page = self.commands[cmd].execute()
page.render()
Something like that, anyway. The idea here is that instead of having a
servlet for every page, I can have one servlet which, depending on the
results of my business logic, can "redirect" (or in this case, return
the appropriate response/presentation page).
For instance, if, when I try to add an "item," something goes wrong, I
can hand back the "add form" page, or an "error" page, or some other
thing, depending.
What would really be cool is if I can use the "WebKit.Page" object (and
descendents) for this sort of thing. When I tried it, though, it didn't
work. I can use the Redirect method to call another servlet existing in
another file, which I don't want to have to do. I tried importing a
"WebKit.Page" derived subclass, and calling its .writePart() methods,
but got an "AttributeError: HomePage instance has no attribute
'_response'" error.
Given all this context, can I use the Page classes for this sort of
thing?
Keith
|