FrontController implementation for JSP pages
I am developing a simple website with few JSP pages. Each jsp does have a dynamic data that needs be read from XML before they redered on to the开发者_开发百科 browser. Though MVC pattern such as Struts2 is more appropriate here, I don't want to implement it for a simple web application.
For this purpose I just want to implement FrontController Pattern which is sufficient for managing the jsp pages with few Helper Classes.
What I want is to have a Centralized Controller for all JSP pages. if user try to acccess any jsp page, then it should first go to the Controller. So I tried to implement a servlet with URL pattern "/pages/*.jsp" where /pages contains all jsp pages in webcontent.
The problem is, the controller is being invoked each time when there is a call for .jsp file, but when I try to disatch it to the jsp page(ex /pages/homepage.jsp) it goes into indefinite loop. It is obvious that each jsp page call will always comes to controler again.
So is there any other way that we can implement the centralized controller for this situation.
Thanks in advance.
I guess your only problem is that you need to read a XML file before each and request is processed.
If this is only the case than Filters are best suited.
But in case there are more that needs to be done and you really need a centralized control on all request than you can do anyone of the following: -
Struts (it doesn't matter that your project is small or big, but using a predefined and proven pattern is always useful).
In your Controller put a mapping of logical URL's with Physical URL's and now put your mapping to Logical URL's and not the physical URL's.
精彩评论