Hi, I'm currently developing an app in GAE/J using simple JSP+Servlet and JDO.
I'm trying to come up with a simple MVC-style
pattern where a request will hit a
servlet and the servlet will either forward() (via RequestDispatcher) the end result to a
JSP or the response will sendRedirect() to another JSP page.
One of the thing I'd like to do is to get the JDO PersistenceManager in init() method and close the persistence manager on destroy() method. So here's roughly how it works:
- init() => initialize a persistence manager (from a factory) as a member variable of the current servlet
- doGet()/doPost() => perform query/processing then either forward or redirect to another servlet/jsp
- destroy() => close the persistence manager
The problem starts with the redirect/forward. It appears that if I do forward()/include() (via RequestDispatcher) or sendRedirect(), the destroy() method of the current servlet (that calls the method) will not be executed.
I read somewhere that forward() will not go back to the original Servlet while include() does. I did try both and they seem to behave the same.
If relying on destroy() to close a persistence manager is not a good idea then perhaps I should shift all the queries to the model? Let's say I have a simple model object called Model. If the queries are part of the object, perhaps I should do something like "getById()" in which the PersistenceManager is created and destroyed within that method.
Thanks,
Ed