We seem to have solved this little problem.
Thanks to Geoff, who set us on the right path.
The critical piece of information that we didn't really grok is that the
redirect is simply an HTTP header that is accumulated, much like the html is
accumulated via all of the self.writeln() commands. Therefore, just calling
the redirect doesn't actually change execution, it just changes the eventual
browser output.
It seems logical now, but looking back, we sort of thought of the
response.sendRedirect() similarly to a break in a for loop.
To emulate that sort of behavior, I suppose we could flush() the response at
that point, but that seems kinda ugly and unpredictable... here's what we
came up with:
Basically, we conditionalized the whole writeHTML block of the servlet. We
have a subclass of Page() that looks something like this:
class Subclass(Page):
def awake(self):
do some other stuff that builds state, including:
- get some user messages out of session for display
- check security clearance
- stuff like that...
- call super class awake()
-- this eventually executes submit
def submit(self,fields):
- this eats the form that was posted (led to the original diagnosis)
- makes some user messages
- sets a FLAG : self.pendingRedirect = 1
def writeHTML(self):
if not self.pendingRedirect:
Page.writeHTML(self)
else:
#possible alternative output here
pass
def sleep(self):
- sync() session, including storing those user messages we had
- do application specific config setting saves
- look for flag self.pendingRedirect,
- if it's there, do actual self.response().sendRedirect('url')
- call super class sleep()
Of course, Geoff recommended just looking in the servlet's headers store to
see if one called "Location" was there, but setting an actual english-like
boolean flag makes the code easier to read for folks like me that don't have
an intimate understanding of the webkit internals.
It seems pretty simple to look at it now, but it was difficult to arrive at.
Coming from the IIS/ASP totally-linear execution world, we expected that
when a redirect() happened, all action would stop and the next servlet would
start... but, the "hidden" servlet used up some input that we expected to
see on the next page.
Again, I think that if we had a better understanding of the flow of a
servlet process, we'd have been able to arrive at this conclusion ourselves.
I am going to read over Ian's "anatomy" document, and re-read the Python-9
paper, and see if I can use the results to make a flow diagram illustration.
If I get it right, we can add it to the communal documentation.
Thanks everyone; it's amazing how good the level of support is in this list.
- Matt
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss