JSP Architecture


As far as architecture of JSP is concerned, it may be seen as a high-level abstraction of Java-Servlets. At runtime, JSPs are translated into servlets. Web server needs a container to process JSP pages commonly known as JSP engine. It is responsible for intercepting requests for JSP pages.

A JSP container works with the Web Server to provide the runtime environment and other services a JSP needs. JSP can be used independently or as the view component of a server-side model-view-controller design, normally with Java Beans as the model and Java Servlets as the controller. JSP allows Java code and certain pre-defined actions to be interleaved with static markup content as HTML, with the resulting page being complied and executed on the server to deliver a document.

The compiled pages, as well as any dependent Java libraries, contain Java byte code. Like any other Java program, they are executed within a JVM that interacts with the server's host OS. The web container creates JSP implicit objects like pageContext, servletContext, session, request and response.



Following steps explain how web pages are created using JSP:
1. Just like a normal page, browser sends HTTP request to the web browser.
2. The web server recognizes that the HTTP request is for a JSP page and forwards it to a JSP engine. This happens with the help of URL or JSP which ends with .jsp.
3. JSP engine loads the JSP page from disk and converts it into a servlet content.
4. Now the JSP engine complies the servlet into an executable class and forwards the original request to a servlet engine.
5. Servlet engine which is the part of web server loads the servlet class and executes it. During execution, the servlet produces an output in HTML format, which is passed to the web server inside the HTTP response.
6. The web server forwards the HTTP response to the browser in terms of static HTML content.
7. Finally web browser handles the dynamically generated HTML page inside the HTTP response exactly as if it were a static page.


Given diagram explains all of the above steps: