Search code examples
springjspseparation-of-concerns

too many jsp files in spring


This is a hypothetical question as in i haven't encountered it yet but i'm very curious about it. What if I had 100 jsp files (it is a big web application) how can i separate my jsp files? What is the suggested practice in this kind of situation? I mean, if i put my jsps under the web-inf, wouldn't the project be bloated? so can i put my jsps in another project and then reference it? I couldn't find anything on the web, all of them described putting all jsps under the web-inf folder.


Solution

    • If you put your JSPs within WEB-INF, then it won't be accessed directly by entering the url in the browser.
    • By putting your JSP in WEB-INF, you can access that JSP only from other servlet of JSP by request dispatching or forwarding.

    You cannot do

     www.someSite.com/WEB-INF/somePage.jsp
    

    but if you put your somePage.jsp in root folder, then you can access by

     www.someSite.com/somePage.jsp
    

    For separation of concerns, You can separate according to modules and the type also.

    • If some of your pages are just headers and footers, then put them in folders called header and footer
    • If some of your pages are related to one Shopping module, then put in shopping module and likewise for other modules.