Does the length of the JSP file effect performance??


Web tier: servlets, JSP, Web frameworks: Does the length of the JSP file effect performance??

  1. Does the length of the JSP file effect performance?? (2 messages)

    Does the length of the JSP file effect performance??

    I have been asked to improve the performance of some jsp files. These files are written in the old fashion where they are if blocks for generating different screens in the same jsp page. So the jsp file is pretty large - 2000 line of code, though each screen that comes up uses only maybe 200 lines.

    Would there be any effect on performance?? The entire compiled servlet would be loaded, right??

    Would splitting them up into different jsps improve performance???

  2. From a pure technical standpoint, I'm not sure if simply having a shorter compiled servlet would improve performance but from a manageability standpoint having JSPs with 2000 lines of code is DEFINITELY going to be a bear to manage.

    It sounds like you are mixing in a substantial amount of logic in your page which is actually not a "recommended" approach. JSPs ideally should just be for UI presentation where JSP/custom tags can render dynamic content.

    If your logic in your page is literally to show one page or another such as:

    if (condition 1)
     Show page 1
    else if (condition 2)
     Show page 2

    Then using an MVC approach is a very good way to handle this where a front end controller servlet handles the different conditions and then routes to the approriate page. Struts is a perfectly good framework for following an MVC approach.

    Here are my recommendations:

    1. Try to reduce your JSPs down to just presentation only. You should definitely try to reduce, if not eliminate, business or interface logic in your pages.

    Place your business logic in the "mid-tier/business-tier" as much as possible.

    For simple page based logic, I'd recommend using JSTL as opposed to raw scriptlets.. Using tags are always better than raw Java code in your pages.

    2. If you have distinct portions which represent different fundamental operations such as "edit", "browse" "input" etc. then I'd definitely break them into distinct pages; edit.jsp, browse.jsp, input.jsp..

    3. If you have distinct yet smaller portions of JSP content which are conditionally shown, then I would recommend breaking these into re-usable fragments and using JSP includes to optionally render them.

    4. Definitely consider using an Model-View-Controller design using the Struts framework.

    Here are some links to check out on J2EE Web tier design as well Struts..

    Check out the "Web-Tier" section in this online book:

    To learn more about Struts:

    Hope this helps..
  3. HI Chris,

    Thank you for the info. I have used struts before and did all the things you mentioned. I am a great fan of MVC and struts myself. But restructuring is not an option here. So cant do that even though I really want to - :(

    I am just looking for ways to quickly improve performance without redoing the whole thing. Was wondering if the length of the jsp file had anything to do with it!

    Thank you.