Where to place JSP file?

Let's first understand what is JSP file and where does it processed and then we will discuss where to place JSP files(best practice).

What is a JSP File?

JavaServer page (JSP) file is a template for a Web page that uses Java code to generate an HTML document dynamically. JSPs are run in a server-side component known as a JSP container, which translates them into equivalent Java servlets.

Well, a JSP file is simply an HTML page with some Java code sprinkled in and it basically gives you dynamic content that you can include on your page.
So in the below diagram here, this is a basic JSP file. It has some HTML code, some Java code, you can make some more HTML code, and so on.
The end result is that you'll have an HTML page with content that's generated by some Java code.

Where is the JSP Processed?

  • JSP file is actually processed on the server. For example, the JSP file can be processed on a web server or application servers like a tomcat server or Glassfish or JBoss, etc.
  • Finally, when JSP file processing completed, the result of the Java code is actually included in the HTML returned to the browser.
Look at the above diagram, we have a web browser, we make a request for a JSP page, it goes across, the JSP pages processed by a server and then the results of that Java code will generate HTML and that those result will actually return back to the web browser. And if returned back to the browser, just plain HTML.

Where to place the JSP file?

  • When we create a new eclipse dynamic project that has a WebContent folder, we place the file there.
  • JSP file must have a .jsp extension.
  • In enterprise J2EE web applications, it is recommended to keep JSP files inside the WEB-INF folder.

In summary, always keep JSP files under WebContent/WEB-INF folder.