asked in JSP by (58.6k points)

1 Answer

Some of the JSP best practices are:

  1. Avoid scripting elements in JSP pages. If JSP EL, action elements and JSTL not serve your needs then create custom tags.
  2. Use comment properly, use JSP comments for code level or debugging purpose so that it’s not sent to client.
  3. Avoid any business logic in JSP page, JSP pages should be used only for response generation for client.
  4. Disable session creation in JSP page where you don’t need it for better performance.
  5. Use page, taglib directives at the start of JSP page for better readability.
  6. 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.
  7. Proper exception handling using JSP error pages to avoid sending container generated response incase JSP pages throw exception in service method.
  8. 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.
  9. 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.
answered by (58.6k points)

Java Interview Questions and Answers 2018

>
...