{"id":28207,"date":"2022-03-04T09:18:40","date_gmt":"2022-03-04T09:18:40","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=28207"},"modified":"2022-12-23T06:48:13","modified_gmt":"2022-12-23T06:48:13","slug":"what-is-jsp-and-how-it-works-an-overview-and-its-use-cases","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/what-is-jsp-and-how-it-works-an-overview-and-its-use-cases\/","title":{"rendered":"What is jsp and How it works? An Overview and Its Use Cases"},"content":{"rendered":"<h3>History &amp; Origin of\u00a0 jsp<\/h3>\n<p>JSP, a specification of Sun Microsystems,\u00a0<b>first appeared in 1998<\/b>. The official versions, 1.0 and 1.1, both appeared in 1999, and both were very popular. The current version, 1.2, appeared in 2001, and is the most popular implementation yet; this is the version we&#8217;ll be using in this book.<\/p>\n<div id=\"WEB_ANSWERS_RESULT_12_yrkhYs6xOMXG-QaBtoYY__53\">\n<div class=\"wDYxhc NFQFxe viOShc LKPcQc\" data-md=\"25\">\n<div class=\"HwtpBd gsrt PZPZlf kTOYnf\" role=\"heading\" data-hveid=\"CDYQAA\" data-ved=\"2ahUKEwjOvuLp8av2AhVFY94KHQGbAQMQtwcoAHoECDYQAA\">\n<div class=\"Z0LcW AZCkJd d2J77b\" data-tts=\"answers\" data-tts-text=\"Sun Microsystems\">\n<div class=\"IZ6rdc\">Sun Microsystems<\/div>\n<\/div>\n<div class=\"yxAsKe\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"WEB_ANSWERS_RESULT_13_yrkhYs6xOMXG-QaBtoYY__54\">\n<div class=\"wDYxhc\" data-md=\"135\">\n<div class=\"Crs1tb\" data-hveid=\"CDsQAA\">\n<div class=\"iKJnec\" role=\"heading\">Released in 1999 by\u00a0<b>Sun Microsystems<\/b>, JSP is similar to PHP and ASP, but uses the Java programming language.<\/div>\n<\/div>\n<\/div>\n<h3 role=\"heading\">What is jsp?<\/h3>\n<p>JavaServer Pages (JSP) is\u00a0<b>a Java standard technology that enables you to write dynamic, data-driven pages for your Java web applications<\/b>. JSP is built on top of the Java Servlet specification. The two technologies typically work together, especially in older Java web applications.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-28209 size-full\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/jsp-overview-100786478-medium.jpg\" alt=\"\" width=\"300\" height=\"149\" \/><\/p>\n<p>While JSP may not be your first choice for building dynamic web pages, it is a core Java web technology. JSP pages are relatively quick and easy to build, and they interact seamlessly with Java servlets in a\u00a0<a href=\"https:\/\/www.javaworld.com\/article\/3313114\/learn-java\/what-is-a-java-servlet-request-handling-for-java-web-applications.html\" target=\"_blank\" rel=\"noopener\">servlet container<\/a>\u00a0like Tomcat. You will encounter JSP in older Java web applications, and from time to time you may find it useful for building simple, dynamic Java web pages. As a Java developer, you should at least be familiar with JSP.<\/p>\n<p>This article will be a quick introduction to JavaServer Pages, including the\u00a0<a href=\"https:\/\/www.tutorialspoint.com\/jsp\/jsp_standard_tag_library.htm\" rel=\"nofollow noopener\" target=\"_blank\">JSP Standard Tag Library (JSTL)<\/a>. Examples show you how to write a simple HTML page, embed JSP tags to connect to a Java servlet, and run the page in a servlet container.<\/p>\n<p>See previous articles in this series to learn more about\u00a0<a href=\"https:\/\/www.javaworld.com\/article\/3313114\/learn-java\/what-is-a-java-servlet-request-handling-for-java-web-applications.html\" target=\"_blank\" rel=\"noopener\">Java servlets<\/a>\u00a0and\u00a0<a href=\"https:\/\/www.javaworld.com\/article\/3322533\/enterprise-java\/what-is-jsf-introducing-javaserver-faces.html\" target=\"_blank\" rel=\"noopener\">JavaServer Faces<\/a>.<\/p>\n<aside class=\"sidebar\">\n<h3 class=\"body\">JSP in Jakarta EE<\/h3>\n<p>Following the release of Java EE 8, Oracle moved stewardship of Java Enterprise Edition (Java EE) to the Eclipse Foundation. Going forward, the Java enterprise platform has been rebranded as\u00a0<a href=\"https:\/\/www.eclipse.org\/community\/eclipse_newsletter\/2018\/may\/javaenterprise-newhome.php\" rel=\"nofollow noopener\" target=\"_blank\">Jakarta EE<\/a>. Along with the Java Servlet and JSF specifications, JSP is one of the Java web technologies included for ongoing support and upgrades in Jakarta EE.<\/p>\n<\/aside>\n<h2>Writing JSP pages<\/h2>\n<p>A simple JSP page (.jsp) consists of HTML markup embedded with JSP tags. When the file is processed on the server, the HTML is rendered as the application view, a web page. The embedded JSP tags will be used to call server-side code and data. The diagram in Figure 1 shows the interaction between HTML, JSP, and the web application server.<\/p>\n<h4>Listing 1. A simple JSP page<\/h4>\n<pre class=\"prettyprint prettyprinted\"><code>\r\n<span class=\"tag\">&lt;html&gt;<\/span>\r\n  <span class=\"tag\">&lt;body&gt;<\/span>\r\n    <span class=\"tag\">&lt;p&gt;<\/span><span class=\"pln\">${2 * 2} should equal 4<\/span><span class=\"tag\">&lt;\/p&gt;<\/span>\r\n  <span class=\"tag\">&lt;\/body&gt;<\/span>\r\n<span class=\"tag\">&lt;\/html&gt;<\/span><\/code><\/pre>\n<p>In Listing 1, you see a block of HTML that includes a\u00a0<em>JSP expression<\/em>, which is an instruction to the Java server written using\u00a0<a href=\"https:\/\/docs.oracle.com\/javaee\/6\/tutorial\/doc\/gjddd.html\" rel=\"nofollow noopener\" target=\"_blank\">Expression Language (EL)<\/a>. In the expression &#8220;<code>${2 * 2}<\/code>&#8220;, the &#8220;<code>${}<\/code>&#8221; is JSP syntax for interpolating code into HTML. When executed, the JSP will output the results of executing whatever is inside the expression. In this case, the output will be the number 4.<\/p>\n<h3>How jsp works aka jsp architecture?<\/h3>\n<h2>JSP Architecture<\/h2>\n<div class=\"text\">\n<p><a href=\"https:\/\/www.geeksforgeeks.org\/introduction-to-jsp\/\" target=\"_blank\" rel=\"noopener\">JSP<\/a>\u00a0architecture gives a high-level view of the working of JSP. JSP architecture is a 3 tier architecture. It has a Client, Web Server, and Database. The client is the web browser or application on the user side. Web Server uses a JSP Engine i.e; a container that processes JSP. For example, Apache Tomcat has a built-in JSP Engine. JSP Engine intercepts the request for JSP and provides the runtime environment for the understanding and processing of JSP files. It reads, parses, build Java Servlet, Compiles and Executes Java code, and returns the HTML page to the client. The webserver has access to the Database. The following diagram shows the architecture of JSP.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/media.geeksforgeeks.org\/wp-content\/uploads\/20210702122023\/m6.png\" width=\"1000\" \/><\/p>\n<p>Now let us discuss JSP which stands for Java Server Pages. It is a server-side technology. It is used for creating web applications. It is used to create dynamic web content. In this JSP tags are used to insert JAVA code into HTML pages. It is an advanced version of Servlet Technology. It is a Web-based technology that helps us to create dynamic and platform-independent web pages. In this, Java code can be inserted in HTML\/ XML pages or both. JSP is first converted into a servlet by JSP container before processing the client\u2019s request.\u00a0<strong>JSP Processing\u00a0<\/strong>is illustrated and discussed in sequential steps prior to which a pictorial media is provided as a handful pick to understand the JSP processing better which is as follows:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/media.geeksforgeeks.org\/wp-content\/uploads\/20210702122047\/m5.png\" width=\"1000\" \/><\/p>\n<p><strong>Step 1:<\/strong>\u00a0The client navigates to a file ending with<i><strong>\u00a0<\/strong><\/i>the<strong>\u00a0<\/strong><a href=\"https:\/\/www.geeksforgeeks.org\/difference-between-servlet-and-jsp\/\" target=\"_blank\" rel=\"noopener\"><i><strong>.jsp extension<\/strong><\/i>\u00a0<\/a>and the browser initiates an HTTP request to the webserver. For example, the user enters the login details and submits the button. The browser requests a status.jsp page from the webserver.<\/p>\n<div id=\"AP_G4GR_5\"><\/div>\n<p><strong>Step 2:<\/strong>\u00a0If the compiled version of JSP exists in the web server, it returns the file. Otherwise, the request is forwarded to the JSP Engine. This is done by recognizing the URL ending with\u00a0<strong>.jsp\u00a0<\/strong>extension.<\/p>\n<p><strong>Step 3:<\/strong>\u00a0The JSP Engine loads the JSP file and translates the JSP to Servlet(Java code). This is done by converting all the template text into println() statements and JSP elements to Java code. This process is called\u00a0<strong>translation.<\/strong><\/p>\n<p><strong>Step 4:<\/strong>\u00a0The JSP engine compiles the Servlet to an executable\u00a0<strong>.class\u00a0<\/strong>file. It is forwarded to the Servlet engine. This process is called\u00a0<strong>compilation\u00a0<\/strong>or\u00a0<strong>request processing phase.<\/strong><\/p>\n<p><strong>Step 5:<\/strong>\u00a0The\u00a0<strong>.class\u00a0<\/strong>file is executed by the Servlet engine which is a part of the Web Server. The output is an HTML file. The Servlet engine passes the output as an HTTP response to the webserver.<\/p>\n<p><strong>Step 6:<\/strong>\u00a0The web server forwards the HTML file to the client\u2019s browser.<\/p>\n<h2>Use case of jsp.<\/h2>\n<p>JSPs are usually used to\u00a0<b>deliver HTML and XML documents<\/b>, but through the use of OutputStream, they can deliver other types of data as well. The Web container creates JSP implicit objects like request, response, session, application, config, page, pageContext, out and exception.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-28214 size-full\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/220px-JSP_Model_2.svg_.png\" alt=\"\" width=\"220\" height=\"252\" \/><\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<h3>Feature and Advantage of using\u00a0 jsp.<\/h3>\n<p><strong>JSP pages are more advantageous than Servlet:<\/strong><\/p>\n<ul>\n<li>They are easy to maintain.<\/li>\n<li>No recompilation or redeployment is required.<\/li>\n<li>JSP has access to entire API of JAVA .<\/li>\n<li>JSP are extended version of Servlet.<\/li>\n<\/ul>\n<p><strong>Features of JSP<\/strong><\/p>\n<ul>\n<li><b>Coding in JSP is easy<\/b>\u00a0:- As it is just adding JAVA code to HTML\/XML.<\/li>\n<li><b>Reduction in the length of Code<\/b>\u00a0:- In JSP we use action tags, custom tags etc.<\/li>\n<li><b>Connection to Database is easier<\/b>\u00a0:-It is easier to connect website to database and allows to read or write data easily to the database.<\/li>\n<li><b>Make Interactive websites<\/b>\u00a0:- In this we can create dynamic web pages which helps user to interact in real time environment.<\/li>\n<li><b>Portable, Powerful, flexible and easy to maintain<\/b>\u00a0:- as these are browser and server independent.<\/li>\n<li><b>No Redeployment and No Re-Compilation<\/b>\u00a0:- It is dynamic, secure and platform independent so no need to re-compilation.<\/li>\n<li><b>Extension to Servlet<\/b>\u00a0:- as it has all features of servlets, implicit objects and custom tags<strong>JSP syntax<\/strong><br \/>\nSyntax available in JSP are following<\/p>\n<ol>\n<li><b>Declaration Tag<\/b>\u00a0:-It is used to declare variables.\n<pre><b>Syntax:- <\/b>\r\n&lt;%!  Dec var  %&gt;\r\n<b>Example:-<\/b>\r\n&lt;%! int var=10; %&gt;\r\n<\/pre>\n<\/li>\n<li><b>Java Scriplets<\/b>\u00a0:- It allows us to add any number of JAVA code, variables and expressions.\n<pre><b> Syntax:- <\/b>\r\n&lt;% java code %&gt;\r\n<\/pre>\n<\/li>\n<li><b>JSP Expression<\/b>\u00a0:- It evaluates and convert the expression to a string.\n<pre><b> Syntax:- <\/b>\r\n&lt;%= expression %&gt; \r\n<b> Example:- <\/b>\r\n&lt;% num1 = num1+num2 %&gt; \r\n<\/pre>\n<\/li>\n<li><b>JAVA Comments<\/b>\u00a0:- It contains the text that is added for information which has to be ignored.\n<pre><b> Syntax:- <\/b>\r\n&lt;% -- JSP Comments %&gt;\r\n<\/pre>\n<p><strong>Process of Execution<\/strong><br \/>\nSteps for Execution of JSP are following:-<\/p>\n<div id=\"AP_G4GR_5\"><\/div>\n<ul>\n<li>Create html page from where request will be sent to server eg try.html.<\/li>\n<li>To handle to request of user next is to create .jsp file Eg. new.jsp<\/li>\n<li>Create project folder structure.<\/li>\n<li>Create XML file eg my.xml.<\/li>\n<li>Create WAR file.<\/li>\n<li>Start Tomcat<\/li>\n<li>Run Application<\/li>\n<\/ul>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/media.geeksforgeeks.org\/wp-content\/uploads\/jsp.jpg.jpg\" \/><\/p>\n<p><strong>Example of Hello World<\/strong><br \/>\nWe will make one .html file and .jsp file<\/p>\n<pre><b>demo.jsp<\/b>\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;meta http-equiv=\"Content-Type\" content=\"text\/html; charset=ISO-8859-1\"&gt;\r\n&lt;title&gt;Hello World - JSP tutorial&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n    &lt;%= \"Hello World!\" %&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p><strong>Advantages of using JSP<\/strong><\/p>\n<ul>\n<li>It does not require advanced knowledge of JAVA<\/li>\n<li>It is capable of handling exceptions<\/li>\n<li>Easy to use and learn<\/li>\n<li>It can tags which are easy to use and understand<\/li>\n<li>Implicit objects are there which reduces the length of code<\/li>\n<li>It is suitable for both JAVA and non JAVA programmer<\/li>\n<\/ul>\n<p><strong>Disadvantages of using JSP<\/strong><\/p>\n<ul>\n<li>Difficult to debug for errors.<\/li>\n<li>First time access leads to wastage of time<\/li>\n<li>It\u2019s output is HTML which lacks features.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/div>\n<h2>Best Alternative of jsp.<\/h2>\n<p>For JSP there are other alternatives. For example you could program all your web pages with Servlet, even thought it is not very professional but it is possible. There were\u00a0<b>Struts, tapestry<\/b>\u00a0and some other alternative. The one I have used and mastered is JSF (Java server faces).<\/p>\n<p>Servlets are the Java programs that\u00a0run\u00a0on the Java-enabled web server or application server. They are used to handle the request obtained from the\u00a0webserver, process the request, produce the response, then send\u00a0the\u00a0response back to the\u00a0webserver. Below are some alternatives\u00a0to\u00a0servlets:<\/p>\n<h3>1. Common Gateway Interface (CGI)<\/h3>\n<p>It is the most typical server-side solution. CGI application is an independent program that receives requests from the online server and sends it back to the webserver. The use of CGI scripts was to process forms. it\u2019s the technology that permits web browsers to submit forms and connect with programs over an internet server. The common gateway interface provides an even way for data to be passed from the user\u2019s request to the appliance program and back to the user.<\/p>\n<p><strong>Example:\u00a0<\/strong>When you fill-up the shape and submit the shape applying, click the submit button and it goes, what are the results from this level is CGI.<\/p>\n<p>A common<strong>\u00a0<\/strong>problem in this when a new process is created every time the web server receives a CGI request so it results in a delay of response time.<\/p>\n<div id=\"AP_G4GR_5\"><\/div>\n<h3>2. Proprietary API<\/h3>\n<p>Many proprietary web servers have built-in support for server-side programming. These also are called non-free software, or closed-source software, is computer software that the software\u2019s publisher or another person retains property right usual copyright of the ASCII text file, but sometimes patent rights. It\u2019s a software library interface \u201cspecific to at least one device or, more likely to a variety of devices within a specific manufacturer\u2019s product range\u201d. The motivation for employing a proprietary API is often vendor lock-in or because standard APIs don\u2019t support the device\u2019s functionality.<\/p>\n<p><strong>Examples:\u00a0<\/strong>Netscape\u2019s NSAPI, Microsoft\u2019s ISAPI, and O\u2019Reilly\u2019s WSAPI.<\/p>\n<p><strong>Drawback:<\/strong>\u00a0Most of these are developed in C\/C++ and hence can contain memory leaks and core dumps that can crash the webserver.<\/p>\n<h3>3. Active Server Pages (ASP)<\/h3>\n<p>Microsoft\u2019s ASP is another technology that supports server-side programming. Only Microsoft\u2019s Internet Information Server (IIS) supports this technology which isn\u2019t free. They work with simple HTML pages, the client (a web surfer) requests an internet page from a server. The server just sends the file to the client, and therefore the page is shown on the client\u2019s browser.\u00a0ASP is now obsolete and replaced with ASP.NET. ASP.NET may be a compiled language and relies on the<a href=\"https:\/\/www.geeksforgeeks.org\/introduction-to-net-framework\/\" target=\"_blank\" rel=\"noopener\"><strong>\u00a0.NET Framework<\/strong><\/a>, while ASP is strictly an interpreted language.<\/p>\n<h3>4. Serverside JavaScript<\/h3>\n<p>It is another alternative to servlets. The sole known servers that support it are Netscape\u2019s Enterprise and FastTrack servers. This ties you to a specific vendor. \u00a0Server-side JavaScript can be a JavaScript code that runs over a server local resources and it is similar to Java or C#, but the syntax is predicated on JavaScript.<\/p>\n<p><strong>Example:\u00a0<\/strong>An ideal of this is often Node.JS. The advantage of server-side scripting is that the ability to highly customize the response supported the user\u2019s requirements, access rights, or queries into data stores.<\/p>\n<h2>Best Resources, Tutorials and Guide for jsp.<\/h2>\n<ol>\n<li><a href=\"https:\/\/www.edureka.co\/blog\/servlet-and-jsp-tutorial\/\" target=\"_blank\" rel=\"noopener\">edureka<\/a><\/li>\n<li><a href=\"https:\/\/www.tutorialspoint.com\/jsp\/index.htm\" target=\"_blank\" rel=\"noopener\">tutorialspoint.com<\/a><\/li>\n<li><a href=\"https:\/\/www.udemy.com\/topic\/jsp\/\" target=\"_blank\" rel=\"noopener\">udemy.com<\/a><\/li>\n<\/ol>\n<h2>Free Video Tutorials of jsp<\/h2>\n<iframe loading=\"lazy\"  id=\"_ytid_73601\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/xve6QEgIR-0?enablejsapi=1&autoplay=0&cc_load_policy=0&cc_lang_pref=&iv_load_policy=1&loop=0&rel=1&fs=1&playsinline=0&autohide=2&theme=dark&color=red&controls=1&disablekb=0&\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe>\n<iframe loading=\"lazy\"  id=\"_ytid_54429\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/7TOmdDJc14s?enablejsapi=1&autoplay=0&cc_load_policy=0&cc_lang_pref=&iv_load_policy=1&loop=0&rel=1&fs=1&playsinline=0&autohide=2&theme=dark&color=red&controls=1&disablekb=0&\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe>\n<h2>Interview Questions and Answer for JSP<\/h2>\n<section id=\"what-is-jsp\" class=\"ibpage-article-header\">\n<h3>1. What is JSP?<\/h3>\n<article class=\"ibpage-article\">JSP stands for Java Server Pages. This technology is used to create dynamic web pages in the form of\u00a0<a href=\"https:\/\/www.interviewbit.com\/html-interview-questions\/\" target=\"_blank\" rel=\"noopener noreferrer\">HyperText Markup Language<\/a>\u00a0(HTML). They have embedded Java code pieces in them. They are an extension to the Servlet Technology and generate Servlet from a page. It is common to use both servlets and JSP pages in the same web apps.<\/p>\n<figure class=\"image\"><img decoding=\"async\" class=\"\" src=\"https:\/\/s3.ap-south-1.amazonaws.com\/myinterviewtrainer-domestic\/public_assets\/assets\/000\/000\/535\/original\/what_is_jsp.png?1624444860\" data-src=\"https:\/\/s3.ap-south-1.amazonaws.com\/myinterviewtrainer-domestic\/public_assets\/assets\/000\/000\/535\/original\/what_is_jsp.png?1624444860\" \/><\/figure>\n<\/article>\n<\/section>\n<section id=\"how-does-jsp-work\" class=\"ibpage-article-header\">\n<h3>2. How does JSP work?<\/h3>\n<article class=\"ibpage-article\">The JSP container has a special servlet called the page compiler. All HTTP requests with URLs that match the .jsp file extension are forwarded to this page compiler by the configuration of the servlet container. The servlet container is turned into a JSP container with this page compiler. When a .jsp page is first called, the page compiler parses and compiles the .jsp page into a servlet class. The JSP servlet class is loaded into memory on the successful compilation. For the subsequent calls, the servlet class for that .jsp page is already in memory. Hence, the page compiler servlet will always compare the timestamp of the JSP servlet with the JSP page. If the .jsp page is more current, recompilation is necessary. With this process, once deployed, JSP pages only go through the time-consuming compilation process once.<\/p>\n<\/article>\n<\/section>\n<section id=\"how-does-jsp-initialization-take-place\" class=\"ibpage-article-header\">\n<h3>3. How does JSP Initialization take place?<\/h3>\n<article class=\"ibpage-article\">When a container loads a JSP, it invokes the jspInit() method before servicing any requests.<\/p>\n<pre><code class=\"language-plaintext hljs\">public void jspInit(){\r\n  \/\/ Initialization code...\r\n}<\/code><\/pre>\n<\/article>\n<\/section>\n<section id=\"use-of-jsp\" class=\"ibpage-article-header\">\n<h3>4. What is the use of JSP?<\/h3>\n<article class=\"ibpage-article\">Earlier, Common Gateway Interface (CGI) was the only tool for developing dynamic web content and was not very efficient. The web server has to create a new operating system process, load an interpreter and a script, execute the script, and then tear it all down again, for every request that comes in. This is taxing for the server and doesn\u2019t scale well when the number of traffic increases.<\/p>\n<p>Alternatives such as ISAPI from Microsoft, and Java Servlets from Sun Microsystems, offer better performance and scalability. However, they generate web pages by embedding HTML directly in programming language code. JavaServer Pages (JSP) changes all of that.<\/p>\n<\/article>\n<\/section>\n<section id=\"jsp-advantages\" class=\"ibpage-article-header\">\n<h3>5. What are some of the advantages of using JSP?<\/h3>\n<article class=\"ibpage-article\">\n<ul>\n<li>Better performance and quality as JSP is a specification and not a product.<\/li>\n<li>JSP pages can be used in combination with servlets.<\/li>\n<li>JSP is an integral part of J2EE, a complete platform for Enterprise-class applications.<\/li>\n<li>JSP supports both scripting and element-based dynamic content.<\/li>\n<\/ul>\n<\/article>\n<\/section>\n<section id=\"java-server-template-engines\" class=\"ibpage-article-header\">\n<h3>6. What is Java Server Template Engines?<\/h3>\n<article class=\"ibpage-article\">A Java servlet template engine is a technology for separating presentation from processing. Template engines have been developed as open-source products to help get HTML out of the servlets. These template engines are intended to be used together with pure code components (servlets) and use only web pages with scripting code for the presentation part.<\/p>\n<p>Two popular template engines are WebMacro (<a href=\"http:\/\/www.webmacro.org\/\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">http:\/\/www.webmacro.org<\/a>) and FreeMarker (<a href=\"http:\/\/freemarker.sourceforge.net\/\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">http:\/\/freemarker.sourceforge.net<\/a>).<\/p>\n<\/article>\n<\/section>\n<section id=\"what-are-servlets\" class=\"ibpage-article-header\">\n<h3>7. What are Servlets?<\/h3>\n<article class=\"ibpage-article\">JSP pages are often combined with servlets in the same application. The JSP specification is based on the Java servlet specification. Simply put, a servlet is a piece of code that adds new functionality to a web server, just like CGI and proprietary server extensions such as NSAPI and ISAPI. Compared to other technologies, servlets have a number of advantages:<\/p>\n<ul>\n<li>Platform and vendor independence<\/li>\n<li>Integration<\/li>\n<li>Efficiency<\/li>\n<li>Scalability<\/li>\n<li>Robustness and security<\/li>\n<\/ul>\n<figure class=\"image image_resized\"><img decoding=\"async\" class=\"\" src=\"https:\/\/s3.ap-south-1.amazonaws.com\/myinterviewtrainer-domestic\/public_assets\/assets\/000\/000\/536\/original\/Servlet.png?1624445871\" data-src=\"https:\/\/s3.ap-south-1.amazonaws.com\/myinterviewtrainer-domestic\/public_assets\/assets\/000\/000\/536\/original\/Servlet.png?1624445871\" \/><\/figure>\n<\/article>\n<\/section>\n<section id=\"life-cycle-of-a-servlet\" class=\"ibpage-article-header\">\n<h3>8. Explain the Life Cycle of a servlet.<\/h3>\n<article class=\"ibpage-article\">A Java class that uses the Servlet Application Programming Interface (API) is a Servlet. The Servlet API consists of many classes and interfaces that define some methods. These methods make it possible to process HTTP requests in a web server-independent manner.<\/p>\n<p>A servlet is loaded when a web server receives a request that should be handled by it. Once a servlet has been loaded, the same servlet instance (object) is called to process succeeding requests. Eventually, the webserver needs to shut down the servlet, typically when the web server itself is shut down.<\/p>\n<p>The 3 life cycle methods are:<\/p>\n<ul>\n<li>public void init(ServletConfig config)<\/li>\n<li>public void service(ServletRequest req, ServletResponse res)<\/li>\n<li>public void destroy( )<\/li>\n<\/ul>\n<p>These methods define the interactions between the web server and the servlet.<\/p>\n<figure class=\"image image_resized\"><img decoding=\"async\" class=\"\" src=\"https:\/\/s3.ap-south-1.amazonaws.com\/myinterviewtrainer-domestic\/public_assets\/assets\/000\/000\/537\/original\/servlet_life_cycle.png?1624445999\" data-src=\"https:\/\/s3.ap-south-1.amazonaws.com\/myinterviewtrainer-domestic\/public_assets\/assets\/000\/000\/537\/original\/servlet_life_cycle.png?1624445999\" \/><\/figure>\n<\/article>\n<\/section>\n<section id=\"types-of-elements-with-java-server-pages\" class=\"ibpage-article-header\">\n<h3>9. What are the types of elements with Java Server Pages (JSP)?<\/h3>\n<article class=\"ibpage-article\">The three types of elements with Java Server Pages (JSP) are directive, action, and scripting elements.<br \/>\n<strong>Following are the Directive Elements:<\/strong><\/p>\n<figure class=\"table\">\n<table>\n<thead>\n<tr>\n<th>Element<\/th>\n<th>Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>&lt;%@ page &#8230; %&gt;<\/td>\n<td>Defines page-dependent attributes, such as scripting language, error page, and buffering requirements.<\/td>\n<\/tr>\n<tr>\n<td>&lt;%@ include &#8230; %&gt;<\/td>\n<td>Includes a file during the translation phase.<\/td>\n<\/tr>\n<tr>\n<td>&lt;%@ taglib &#8230; %&gt;<\/td>\n<td>Declares a tag library, containing custom actions, used on the page.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p><strong>The Action elements are:<\/strong><\/p>\n<figure class=\"table\">\n<table>\n<thead>\n<tr>\n<th>Element<\/th>\n<th>Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>&lt;jsp:useBean&gt;<\/td>\n<td>This is for making the JavaBeans component available on a page.<\/td>\n<\/tr>\n<tr>\n<td>&lt;jsp:getProperty&gt;<\/td>\n<td>This is used to get a property value from a JavaBeans component and to add it to the response.<\/td>\n<\/tr>\n<tr>\n<td>&lt;jsp:setProperty&gt;<\/td>\n<td>This is used to set a value for the JavaBeans property.<\/td>\n<\/tr>\n<tr>\n<td>&lt;jsp:include&gt;<\/td>\n<td>This includes the response from a servlet or JSP page during the request processing phase.<\/td>\n<\/tr>\n<tr>\n<td>&lt;jsp:forward&gt;<\/td>\n<td>This is used to forward the processing of a request to a JSP page or servlet.<\/td>\n<\/tr>\n<tr>\n<td>&lt;jsp:param&gt;<\/td>\n<td>This is used for adding a parameter value to a request given to another servlet or JSP page by using &lt;jsp:include&gt; or &lt;jsp:forward&gt;<\/td>\n<\/tr>\n<tr>\n<td>&lt;jsp:plugin&gt;<\/td>\n<td>This is used to generate HTML that contains the proper client browser-dependent elements which are used to execute an Applet with Java Plugin software.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p><strong>And lastly, the Scripting elements are:<\/strong><\/p>\n<figure class=\"table\">\n<table>\n<thead>\n<tr>\n<th>Element<\/th>\n<th>Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>&lt;% &#8230; %&gt;<\/td>\n<td>Scriptlet used to embed scripting code.<\/td>\n<\/tr>\n<tr>\n<td>&lt;%= &#8230; %&gt;<\/td>\n<td>Expression, used to embed Java expressions when the result shall be added to the response. Also used as runtime action attribute values.<\/td>\n<\/tr>\n<tr>\n<td>&lt;%! &#8230; %&gt;<\/td>\n<td>Declaration used to declare instance variables and methods in the JSP page implementation class.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<\/article>\n<\/section>\n<section id=\"difference-between-jsp-and-javascript\" class=\"ibpage-article-header\">\n<h3>10. What is the difference between JSP and Javascript?<\/h3>\n<article class=\"ibpage-article\">JSP is a server-side scripting language as it runs on the server. Whereas, JavaScript runs on the client. Commonly, JSP is more used to change the content of a webpage, and JavaScript for the presentation. Both are quite commonly used on the same page.<\/p>\n<\/article>\n<\/section>\n<section id=\"jsp-expression-language\" class=\"ibpage-article-header\">\n<h3>11. What is JSP Expression Language (EL)?<\/h3>\n<article class=\"ibpage-article\">Expression Language (EL) was introduced in JSP 2.0. It is a mechanism that simplifies the accessibility of the data stored in Javabean components and other objects like request, session, and application, etc. There are many operators in JSP that are used in EL like arithmetic and logical operators to perform an expression<\/p>\n<\/article>\n<\/section>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>History &amp; Origin of\u00a0 jsp JSP, a specification of Sun Microsystems,\u00a0first appeared in 1998. The official versions, 1.0 and 1.1, both appeared in 1999, and both were very popular. The&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[2],"tags":[],"class_list":["post-28207","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/28207","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=28207"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/28207\/revisions"}],"predecessor-version":[{"id":32449,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/28207\/revisions\/32449"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=28207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=28207"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=28207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}