Hi guys, I was thinking of an elegant solution for this... I have a generic form that sets the timestamp sesseion variable(this is used in sql queries). Now... Since it's generic, it's used in different pages. I need to be returning to one of those pages once the timestamp is set. Ofcourse, I will also need to go into the controller of that particular page first.
I am thinking of creating multiple static variables like this...
and then having a select statement on my controller, I will get a request parameter value and depending on the value of the parameter, I will know which controller to forward to.
If you want to return to the controller before forwarding to any of those 4 pages that you want to go to, depending on a request parameter that sounds more like a 'filter' mechanism to me.
I did something similar in one of my applications and had a filter which implements an interface ( with all the target pages listed as constants) and acted as the controller for all those pages, forwarding to a page based on a request parameter.
Joined: Sep 18, 2005
Why didn't I think of filters! Anyway... If I get the chance to modify my code, I will try your suggestion. I made a temporary solution where I made a bundle(properties file) and put all the KEY=VALUE pairs there and depending on the request parameter, I will get the value of that key like
Hmmm... But there really is a point with what you suggested... Thanks!
Joined: Sep 18, 2005
Hmmm... Isn't a Filter called before the servlet? How can I make the filter forward to that controller ONLY if the servlet is finished with its part(e.g. doing database stuff)?
With a Filter you can examine the Request object first. Then you call doFilter on the FilterChain object which will invoke the next item in the chain (your servlet in this case). When everything down the chain is done, it returns to the point in the Filter AFTER the doFilter call. At THAT point you get to mess around with the Response object.
So, as far as I can see, you could do something like:
[ October 10, 2006: Message edited by: Daniel Dalton ]
Joined: Jan 25, 2005
Originally posted by Timothy Sam: Hmmm... Isn't a Filter called before the servlet? How can I make the filter forward to that controller ONLY if the servlet is finished with its part(e.g. doing database stuff)?
A filter is a sort of a servlet. In fact if you look at the doFilter() method it has a copy of the ServletRequest and ServletResponse objects, which you could use for your control. And also it can be mapped to a url in a much similar way as you map servlets.
and you could use the filter for security as well.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: A controller that forwards to different pages/controllers