{"id":2828,"date":"2019-06-09T21:34:51","date_gmt":"2019-06-09T21:34:51","guid":{"rendered":"http:\/\/softlect.in\/?p=2828"},"modified":"2019-06-15T01:25:20","modified_gmt":"2019-06-15T01:25:20","slug":"java-server-pages","status":"publish","type":"post","link":"http:\/\/softlect.com\/index.php\/java-server-pages\/","title":{"rendered":"Java Server Pages"},"content":{"rendered":"<p>Java server pages is a server-side program which is similar to Java Servlets in design and functionality.\u00a0JSP is written within HTML with scripting elements, directives, and actions.\u00a0JSP program statements are written using Java programming language within HTML Scripting elements.\u00a0JSP offers same features as Java Servlet because JSP is converted to a Java Servlet the first time JSP page is requested by the client.\u00a0There are three methods that are implicitly called when the JSP page is requested.<br \/>\njspInt() :<br \/>\nservice() :<br \/>\njspDestroy() :<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Watch the video tutorial for detailed concepts of Java Server Pages (JSP).<\/p>\n<p><center><br \/>\n<iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/P6EGAB-l4j8\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/center><center><strong>Java Server Pages &#8211; Introduction, Life Cycle, Variables, Methods, Control &amp; Loop Statements<\/strong><\/center><center><\/center>&nbsp;<\/p>\n<p>The above video consists of Introduction to JSP, JSP life-cycle, JSP tags, JSP Architecture, How to write JSP programs with the practical implementation of the JSP program, variables, Methods &amp; control statements and loops in JSP.<\/p>\n<p>These three methods form the part of the JSP lifecycle.\u00a0The JSP life cycle is defined as the process from its creation until the destruction and is similar to the life cycle of a servlet.\u00a0The first phase of the JSP life cycle is<\/p>\n<p><strong>JSP Initialization<\/strong><\/p>\n<p>When a container loads a JSP it invokes the\u00a0<strong>jspInit()<\/strong>\u00a0method before servicing any requests.\u00a0Typically, initialization is performed only once.\u00a0jspInt() method is identical to init() method of Java Servlet and is called the first time JSP page is requested and used to initialize objects and variables that are used throughout the life of the JSP page.<\/p>\n<p><strong>JSP Execution<\/strong><\/p>\n<p>This phase of the JSP life cycle represents all interactions with requests until the JSP is destroyed. Whenever a browser requests a JSP and the page has been loaded and initialized, the JSP engine invokes the\u00a0JSP Service()\u00a0method in the JSP.\u00a0The JSP service() method is similar to service() method of Java Servlet and implicitly called and retrieves a connection to HTTP.\u00a0The\u00a0JSP Service()\u00a0method of a JSP is invoked on a request basis. This is responsible for generating the response for that request.<\/p>\n<p><strong>JSP Shutdown<\/strong><\/p>\n<p>The destruction phase of the JSP life cycle represents when a JSP is being removed from use by a container. The JSP Destroy() method is identical to destroy() method of Java Servlet and is automatically called when JSP page terminates normally. We can Override jspDestroy method when we need to perform any cleanup, such as releasing database connections or closing open files<\/p>\n<p>&nbsp;<\/p>\n<p>JSP programs consist of a combination of HTML and JSP tags.\u00a0JSP Tags define Java code that is executed before the output is sent to the browser.\u00a0The JSP tags begin with &lt;% followed by Java Code and end\u00a0with %&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>There are five types of JSP tags:<\/p>\n<p>Comments Tag: This tag opens with &lt;%&#8211; and closed with &#8211;%&gt; within this tag is the description of the comment.<\/p>\n<p>Declaration Tags: The declaration tag opens with &lt;%! , followed by the declaration of variables, objects and methods. Initialization can also be performed. The declaration closed with %&gt;<\/p>\n<p>Directive Tags:\u00a0The directive tag opens with &lt;%@. This is used for performing specific tasks such as importing java packages. It closes with %&gt;. There are three commonly used directives which we will see in the next slide.<\/p>\n<p>Expressions Tag: This opens with &lt;%= and is used for expression statements. It closes with %&gt;<\/p>\n<p>Scriptlet Tags: This opens with &lt;% and contains java statements. It closes with %&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>As said earlier the directive tag opens with &lt;%@ \u00a0and is used to perform specific tasks.\u00a0There are three commonly used directives.<\/p>\n<p>Page directive<br \/>\ninclude directive<br \/>\ntaglib directive.<\/p>\n<p>&nbsp;<\/p>\n<p>The page directive is used to import java packages.\u00a0Include directive is used for inserting a specific file into a jsp program,\u00a0Taglib directive is used to specify the file that contains a tag library<\/p>\n<p>&nbsp;<\/p>\n<p>The usage of these directives are as follows:<\/p>\n<p>For page directive, an attribute import is used which is used to specify java packages<br \/>\nFor include directive, an attribute file is used to specify the file that is to be included in the JSP program. It can be any file such as HTML or JSP<br \/>\nFor taglib directive, an attribute URI is used to specify the location of the tag library defined.<\/p>\n<p>&nbsp;<\/p>\n<p>Request Object:<\/p>\n<p>The JSP request is an implicit object of type HttpServletRequest i.e. created for each jsp request by the web container. It can be used to get request information such as parameter, header information, remote address, server name, server port, content type, character encoding etc<\/p>\n<p>&nbsp;<\/p>\n<p>Response Object:<\/p>\n<p>In JSP, a response is an implicit object of type HttpServletResponse. The instance of HttpServletResponse is created by the web container for each jsp request.<\/p>\n<p>It can be used to add or manipulate response such as redirect response to another resource, send error etc.<\/p>\n<p>&nbsp;<\/p>\n<p>Session Object:<\/p>\n<p>In JSP, a session is an implicit object of type HttpSession.The Java developer can use this object to set, get or remove attribute or to get session information.<\/p>\n<p>&nbsp;<\/p>\n<p>Watch the video tutorial for detailed concepts of Java Server Pages (JSP).<\/p>\n<p><center><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/qEDKaePCtx8\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/center><center><strong>Java Server Pages &#8211; Implicit Objects, Request, Cookies &amp; Sessions<\/strong><\/center>&nbsp;<\/p>\n<p>The above video consists of JSP implicit objects, Request Object, Cookies and Sessions in JSP.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java server pages is a server-side program which is similar to Java Servlets in design and functionality.\u00a0JSP is written within HTML with scripting elements, directives, and actions.\u00a0This article and video tutorial consist of Introduction to JSP, JSP life-cycle, JSP tags, JSP Architecture, How to write JSP programs with the practical implementation of the JSP program, variables, Methods &#038; control statements and loops in JSP, JSP implicit objects, Request Object, Cookies and Sessions in JSP.\u00a0<\/p>\n","protected":false},"author":1,"featured_media":2918,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[79],"tags":[],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"http:\/\/softlect.com\/index.php\/wp-json\/wp\/v2\/posts\/2828"}],"collection":[{"href":"http:\/\/softlect.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/softlect.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/softlect.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/softlect.com\/index.php\/wp-json\/wp\/v2\/comments?post=2828"}],"version-history":[{"count":12,"href":"http:\/\/softlect.com\/index.php\/wp-json\/wp\/v2\/posts\/2828\/revisions"}],"predecessor-version":[{"id":3396,"href":"http:\/\/softlect.com\/index.php\/wp-json\/wp\/v2\/posts\/2828\/revisions\/3396"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/softlect.com\/index.php\/wp-json\/wp\/v2\/media\/2918"}],"wp:attachment":[{"href":"http:\/\/softlect.com\/index.php\/wp-json\/wp\/v2\/media?parent=2828"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/softlect.com\/index.php\/wp-json\/wp\/v2\/categories?post=2828"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/softlect.com\/index.php\/wp-json\/wp\/v2\/tags?post=2828"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}