JSP - Overview


This article is a series of JSP Tutorial. In this article, we will learn what is JSP technology, JSP file, where to keep JSP file and advantage of JSP.

What is JavaServer Pages?

JavaServer Pages (JSP) is a technology for developing Web pages that support dynamic content. This 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.
So in 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, JSP file can be processed on a web server or application servers like 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.

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

Comments