Introduction to Java Server Pages ( JSP )
- javastrokes
- Feb 28, 2017
- 2 min read
Java Servlet technology is capable of generating dynamic web contents (business data) that are customized according to users' requests (e.g., in response to queries and search requests) with static web pages. But it is a pain to use a Servlet to produce a presentable HTML page. So, Java Server Pages (JSP) was introduced as a complimentary technology to Java Servlet which allows us to add dynamic and static web contents.
As JSP clearly separates the business programming logic from the presentation, this allows the programmers to focus on the business logic, while the web designer to concentrate on the presentation. In a Model-View-Control (MVC) design, servlets are used as gate keeper / controller, which involves complex programming logic. JSPs are used for the view, which deals with presentation and JSP is responsible for collecting the data from end the user and to diplay business data retrieved from the back end. The model could be implemented using Java Beans or Enterprise Java Beans which may interface with a database.

When you create JSP, dynamic contents are generated via programming logic and inserted into the static template. JSP is an integral part of Java EE server-side programming technology that enables the creation of dynamic, platform independent method for building Web-based applications. JSP technology is Java-based, it is platform independent. text-based documents capable of returning dynamic content to a client browser.Contains HTML, XML, programming code, and JSP tags (HTML and XML tags) allowing access to components such as JavaBeans.
And JSP's are similar to HTML files, but they are used for developing web pages, because they have an ability to display dynamic content within Web pages. Using JSP, you can collect input from users through web page forms, present records from a database or another source, and create web pages dynamically.
JSP Architecture, API & Life Cycle You need a JSP engine ie. web container to process JSP pages. A JSP container works with the Web server to provide the run time environment and other services a JSP needs.
The following steps explain how the web server creates the web page using JSP:
As with a normal page, your browser sends a HTTP request to the web server.
The web server recognizes that the HTTP request is for a JSP page and forwards it to a JSP engine. This is done by using the URL or JSP page which ends with .jsp instead of .html.
The JSP engine loads the JSP page from disk and converts it into a servlet content. This conversion is very simple in which all template text is converted to println( ) statements and all JSP elements are converted to Java code that implements the corresponding dynamic behavior of the page.
The JSP engine compiles the servlet into an executable class and forwards the original request to a servlet engine.
A part of the web server called the servlet engine loads the Servlet class and executes it. During execution, the servlet produces an output in HTML format, which the servlet engine passes to the web server inside an HTTP response.
The web server forwards the HTTP response to your browser in terms of static HTML content.
Finally web browser handles the dynamically generated HTML page inside the HTTP response exactly as if it were a static page.

Comments