In a typical web application, most pages share certain common areas such as a navigation menu, a header, footer, and so forth. Since these areas must be identical across pages, maintaining them can be a tedious process since every change in one of these areas must be done in each and every page in the application. To avoid this situation in Java web applications, we can create JSP fragments that can be included in every page. This way if we need to make a change, we only need to do it in the JSP fragment.
In the previous section, we created a login form on both the login.jsp
and loginerror.jsp
pages. If we wish to change the look of this login form, we would have to do it twice, once in each page. This form is a perfect candidate to be extracted to a JSP fragment.