JSP - Overview


This article is a series of JSP Tutorial. In this article, we will learn:
  • What is JSP technology?
  • What is a JSP file?
  • Where to keep JSP file?
  • What are the advantages of using JSP?

What is JavaServer Page (JSP)? 

JSP technology is used to create web applications just like Servlet technology. It can be thought of as an extension to Servlet because it provides more functionality than servlet such as expression language, JSTL, etc.

JSP helps developers insert Java code in HTML pages by making use of special JSP tags, most of which start with <% and end with %>.
A JavaServer Pages component is a type of Java servlet that is designed to fulfill the role of a user interface for a Java web application. Web developers write JSPs as text files that combine HTML or XHTML code, XML elements, and embedded JSP actions and commands.
Using JSP, you can collect input from users through Webpage forms, present records from a database or another source, and create Web pages dynamically.
JSP tags can be used for a variety of purposes, such as retrieving information from a database or registering user preferences, accessing JavaBeans components, passing control between pages, and sharing information between requests, pages, etc.

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.
The below diagram shows a simple JSP structure - 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, JSP files can be processed on a web server or application servers like tomcat server or Glassfish or JBoss, etc.
  • Finally, when JSP file processing is 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 results will actually return back to the web browser. Finally, the web browser will display the HTML page.

Advantages of JSP

JSP pages have all the advantages of servlets:
  • They have better performance and scalability than CGI scripts because they are persistent in memory and multithreaded.
  • No special client setup is required.
  • They have built-in support for HTTP sessions, which makes application programming possible.
  • They have full access to Java technology–network awareness, threads, and database connectivity—without the limitations of client-side applets.
But, in addition, JSP pages have advantages of their own:
  • They are automatically recompiled when necessary.
  • Because they exist in the ordinary Web server document space, addressing JSP pages is simpler than addressing servlets.
  • Because JSP pages are HTML-like, they have greater compatibility with Web development tools.
In the next article, we will learn important JSP scripting elements at JSP Scripting Elements

Free Spring Boot Tutorial | Full In-depth Course | Learn Spring Boot in 10 Hours


Watch this course on YouTube at Spring Boot Tutorial | Fee 10 Hours Full Course

Comments