I have inherited a large legacy web application that is constructed mainly of JSP files linked together with HTML frames. I've been reading Working Effectively with Legacy code and I've found a good small piece to break off in a simple step toward refactoring.
The page is a basic listing page. It queries the database with certain request parameters and displays a list of matching rows along with buttons for applicable actions. Thankfully, most of the business logic on this particular page was already in a POJO, and I've figured out how to replace the presentation logic using JSTL.
From other questions/answers I've read here, the best strategy seems to be to extract the remaining scriptlet into a servlet that does the necessary pre-processing based on the request parameters.
How do I get the servlet to intercept the request and then render the JSP with minimal side-effects on the rest of the application for the time being?
The file I am trying to replace is /welcome/TopFrameList.jsp
.
Answer
If i understood the scenario completely,
Steps:
You could send the control to the Servlet instead of the jsp
directly. i.e. you will have to change the url slightly to point to
Servlet not to the jsp.Let the Servlet pre-process the request parameters (and some
business logic if required)The Servlet then forwards the request
to the jsp which finally renders the view.
That should work, as the only change to the existing application is a slight url change.
Caution: Hoping you have tests which test this part of the application !
No comments:
Post a Comment