Some of the JSP best practices are:
- Avoid scripting elements in JSP pages. If JSP EL, action elements and JSTL not serve your needs then create custom tags.
- Use comment properly, use JSP comments for code level or debugging purpose so that it’s not sent to client.
- Avoid any business logic in JSP page, JSP pages should be used only for response generation for client.
- Disable session creation in JSP page where you don’t need it for better performance.
- Use page, taglib directives at the start of JSP page for better readability.
- Proper use of jsp include directive or include action based on your requirements, include directive is good for static content whereas include action is good for dynamic content and including resource at runtime.
- Proper exception handling using JSP error pages to avoid sending container generated response incase JSP pages throw exception in service method.
- If you are having CSS and JavaScript code in JSP pages, it’s best to place them in separate files and include them in JSP page.
- Most of the times JSTL is enough for our needs, if you find a scenario where it’s not then check your application design and try to put the logic in a servlet that will do the processing and then set attributes to be used in JSP pages.
Please let me know if I have missed any important JSP interview question, I will be adding more to the list in future.
No comments:
Post a Comment