1. Overview

JSP technology is used for developing web applications. JSP was introduced to add more functionalities which were not available in Servlet. It added more functions like expression language, JSTL etc., to simplify web app development.

To understand this technology in depth, you need to have a basic understanding of the Java programming. One can leverage Java Certification to explore basic to advanced level programming with inherited modules like serialization, cloning, abstraction, interfaces, and many more. One clearly understood you will emerge as a big barrel of belief with clear knowledge of Java programming.

A JSP page comprised of HTML and JSP tags which are easy to maintain. Here we can separate both the design and development part of our code leveraging custom tags, pagination, CRUD etc.

2. Java Server Page(JSP) functionalities

JSP has overcome Servlet with its incredible functionalities such as:

2.1 Enhanced Servlet

JSP inherits all the properties of a Servlet. It can achieve all the results same as possible with the Servlet framework. Even it provides various extra features to make the whole development process easier. It includes implicit objects, JSTL, predefined tags etc. JSP provides APIs containing JSP packages named javax.servlet.jsp and javax.servlet.jsp.tagext to include those functionalities.

2.2 Easy to Handle

The traditional Servlet technology includes business and presentation logic together serving a better environment.JSP splits both the business and presentation logic separately providing a clear picture of the application for development.

2.3 Quick Development

Unlike the traditional development like Servlet where we need to compile and execute our code everytime we commit any change also requiring redeployment, JSP pages are modifiable. They don’t require again and again deployment after making an update.

2.4 Require Less Code

JSP application is powered with the cool resources like action tags, custom tags etc. reducing a developers effort for writing bunch of codes.

3. Java Server Page (JSP) Lifecycle

The JSP lifecycle comprised of various steps such as:

  • JSP page translation and compilation
  • Class files loaded through the classloader
  • Instantiation, and Initialization
  • Processing requests
  • Destroy process

In the beginning, translation of the JSP page into servlet is achieved by JSP translator which is an attribute of the web server. The obtained servlet page is gets compiled and converted into the class file. In the end, all the rest processes like initialization and destroy are achieved over the JSP.

Now, since you have understood the life cycle and basics of a JSP page, it’s time to create a simple JSP page to provide an extended knowledge of the modern web development. In the code below you have to write this HTML code including JSP tags. After completion, you have to save this code with the extension .jsp followed by title name. Let’s name it as demo.jsp. Enclose this file in a folder and copy paste that folder in web-apps directory of your apache tomcat server which is responsible for executing your JSP page.

4. Example

4.1 demo.jsp

This file contains scriptlet tag for running your JSP code. The browser will understand the written instructions.


Once executed the output 2 will appear on your browser screen.

4.2 Executing JSP Page

To run your written code follow the procedures written below:

  • Turn on your apache tomcat server.
  • Paste your JSP code in a folder.
  • Deploy that folder over the apache tomcat server.
  • Open your browser and paste URL: http://localhost:portNumber/Rootcontext/filename.jsp
  • Here we will type: http://localhost:portNumber/Rootcontext/demo.jsp
  • It will show the collected output on the browser screen.

Congratulations.. You have successfully executed your first JSP program. Do remember one thing- you don’t need to write the directory structure for executing a JSP file. It is only required in case your code contains Bean classes or other TLD documents or Servlet.

Now, it’s your turn to start writing those innovative ideas striking to your mind with a code. Once you will successfully cover the core modules like scripting elements, implicit objects, APIs, directive elements, exceptions, action, expressions term- you are good for a coding battle. Start building your first web application and turn this dream to a reality. Already, there are more than 1.5 billion websites and applications are available over the worldwide net today.

5. Conclusion

In this article, we have discussed java server pages and it’s added functionalities over servlet. We have also discussed the life cycle of JSP pages with an example.

6. References


Was this post helpful?
Let us know, if you liked the post. Only in this way, we can improve us.