I want to refactor a webapp that consists of very distorted JSPs and servlets. Because we can't switch to a web framework easily we have to keep JSPs and Servlets, and now we are in doubt how to include pages into another and how to setup the use:bean-directives effectively.
At the first step we want to decouple the code for the core-actions and the bean-creation into servlets. The servlets should forward to their corresponding pages, which should use the bean. The problem here is, that each jsp consists of different sub- and sub-sub-jsp that are included into another. Here is a shortend extract (because reality is more complex):
- head
- header
- top
- navigation
- actionspanel
- main
- header
- actionspanel
- foot
- footer
Moreover each jsp (also the header and footer) use dynamic data. For example title and actionspanel can change on each page-reload or do have links and labels that depend on the processing by the preceding servlet.
I know that jsp-include-directives should only be used for static content und should be avoided for dynamic content. But here we have very large pages, that consist of many parts.
Now the core questions: Should I use one big bean for each page, so that each bean holds also data for header and footer beside its core data, so that each subsequent included jsp uses the same bean-directive? For example:
- DirectoryJSP <-> DirectoryBean
- CompareJSP <-> CompareBean
Or should I use one bean for each jsp, so that each bean only holds the data for one jsp and its own purpose. For example:
DirectoryJSP <-> DirectoryBean
HeaderJSP <-> HeaderBean
FooterJSP <-> FooterBean
CompareJSP <-> CompareBean
HeaderJSP <-> HeaderBean
FooterJSP <-> FooterBean
In the second case: should the subsequent beans be a member of the corresponding parent bean, so that only the parent bean is attached as attribute to the request? Or should each bean attached to the request?