0% found this document useful (0 votes)
37 views5 pages

CHP 12 Ej

Java

Uploaded by

Arati Behera
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
37 views5 pages

CHP 12 Ej

Java

Uploaded by

Arati Behera
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 5
Jnvaserver Pages ree 85 CHAPTER OMEMOMSMOMOMOMoHEHCID UNIT - Il t | JAVASERVER i : PAGES | ; omomromcencennenenceaceate [12.1 Introduction to Javaserver Pages | JavaServer Pages (JSP) is a technology used to develop interactive Web pages. JSP was developed by Sun Microsystems and is an improved version of Java servlets. JSP may be developed in a simplified manner and has a wide range of applications. As with most server-based technologies, JSP separates business logic from the presentation layer. JSPs are normal HTML. pages with embedded Java code. To process a JSP file, developers need a JSP engine, which is connected to a Web server. The JSP page is then compiled into a servlet, which is handled by the servlet engine. This phase is known as translation. The servlet engine then loads the servlet class and executes it to create dynamic HTML, which is then sent to the browser. When the next page is requested, the JSP page is precompiled into the servlet and executed, unless the JSP page is changed. When used with Java DataBase Connectivity (DBC), JSP provides a dynamic way to create database-driven websites. [12.2 Why Use Javaserver Pages? 12.2.1 Advantages of JSP over servlet © Extension to Servlet : JSP technology is the extension to servlet technology, We can Use all the features of servlet in JSP. In addition to, we can use implicit objec Predefined tags, expression language and Custom tags in JSP that makes JSP development easy. ® Easy to maintain : JSP can be easily managed because we can easily separate our business logic with presentation logic. In servlet technology, we mix our business logic with the presentation logic. © Fast Development : No need to recompile and redeploy, If JSP page is modified, we don't need to recompile and redeploy the project. The servlet code needs to be updated and recompiled if we have to change the look and feel of the application, © Less code than Servlet : In JSP, we can use a lot of tags such as action tags, JSTL, custom tags etc. that reduces the code, Also, we can use EL, implicit objects ete, © The JSP serves all facilities of Java i.e. write once run anywhere, ° Th implified scripting lang, sed syntax for e1 ; 1s ee JSP uses simplified scripting language based syntax for embedding HTML into Ke q 2 = Enterprise aoa (T-Y.B S617) (Sem. p © JSP containers provide easy coding for accessing standard objects and actions, © The JSP use HTTP as default request /response communication model. 12.1.2 Advantages of JSP over Other Technologies than Servlets © Versus active server pages (ASP) : ASP is given by Microsoft. It is also a tag-baseg programming language. ASP cocle is not portable. However, JSP code is portable because itis written in Java which is portable language. We can use Java for JSP, we need not stick with a particular server product or IIS. © Versus PHP : It is an HTML embedded scripting language and it is also open source software like Java. It is similar to JSP and ASP. It is not suitable for large scal application and banking applications where money transaction occurs because of security reasons. For PHP we have to learn one new language. © Versus JavaScript : JavaScript is in no way related with Java programming, Iti normally used to generate HTML dynamically on the client machine. JavaScript isnot Suitable for network programming and to access server-side resources, Java is more powerful, flexible, reliable and portable than PHP. © Versus HTML : Regular HTML, that is dynamic information. So it does not react to user server side resources. JSP contains both static an contains HTML, [12.2 DISADVANTAGES OF JSP © Output is HTML which is not rich in features, © Difficult to debug/trace errors since compiled. static HTML, does not contain input and is also not fit for accessing id non-static content. As static part, it JSP pages are translated into servlets and © JSP pages require more time when accessed compiled on the server. © Database connectivity is not as easy as it should be. Most of the servlet engine vendors do not support connection pooling natively © Numerous syntax related issues with JSP programming © _ JSP pages require about double the disk [12.3 JSP ws. Servlets © Servlet is faster than JSP, While JSP is slower java code then compile. © In Servlet, if we modify reloading, restarting the server> It means it is time consuming process, While In JSP, if we do a*Y modifications then just we need to clic and. recompilatio” reloading, and restart the server is not required, Servlet isa pure java code. While JSP is tag based approach, : : | © In Servlet, there is no such method for runnin, JavaScript at client si ile In JSP we can use the client side validations using re aes ae | © To run a Servlet you have to make an entry of Servlet me into'the mest descriptor file i.e. web xml file externally, While For running a S30) thaws ePeeed make an entry of Servlet mapping into the webseet i for the first time as they are to be space to hold the page than servlet. than Servlet because it first translate int? fi nd make an entry for JSP file as welcome file ist ile externally, you may oF © Coding of Servlet is harden than JSP. While Codi ea - because it is tag based. odling of JSP is easier than SeF MVC pattern, Servlet plays a controller role, Whit fot ic Mowing cule data ie.in MVC itis view, ® MVC pattern, JSP is used fae 87 sere ges wet Servlet accept all protocol request. While JSP will accept only hitp protocol request. ° In Servlet, Service( ) method need to override. Whi © gervice( ) method. In JSP no need to override In Servlet, by default session management is not enabled we need to enable explicitly. © While In JSP, session management is automatically enabled InServiet we do not have implicit object. I means if we want to use an object then we # eed to get object explicitly form the servlet, While In JSP, we have implicit object support. ; ; : : In Servlet, we need to implement business logic, presentation logic combined, While * in JSP, we can separate the business logic from the presentation logic by uses JavaBean technology. @ InServlet, all package must be imported on top of the servlet. While In JSP, package imported anywhere top, middle and bottom. 124 Life Cycle of AJSP Page ] The page cant outputs the content directly to the browser it relies on early server side processing process which translates JSP page into the JSP Page class. The page class then will handle all the requests made of JSP. [sSP page (isp) ISP Translation Servlet (java) HTTP Servlet loaded JSP Compilation Response Servlet (class) WEB CONTAINER JSPs life cycle can be grouped into following phases 1. JSP Page Translation : A java Servlet file is generated from the JSP source file, This is the first step in its dull multiple phase life cycle. In the translation phase, the container validates the syntax of the JSP page and tag files for correctness. The container interprets the standard directives and actions, and the custom actions referencing tag libraries used in the page. JSP Page Compilation : After the page translation the generated java Servlet file is compiled into a java Servlet class. The translation of implementation class can happen at any time between ini JSP page into the JSP container and the for the target JSP page. Class Loading : The java Servlet class that was compiled from the JSP source is loaded into the container, a JSP page into its ial deployment of the receipt and processing of a client request Execution phase : In this phase the container adlust one or more inst Glass in response to requests and other events, Interface [spPage cannot 7 and « s. Interface JspPage contains jsptnit and ispDeiroy }pethod. The JSP specification has provided a sper interac lspPage for JSP pages serving HTTP sts interfac Ptblepbage for ISP ag 8 equests and this interface containe 5. Initialization : jspinit() method is i : called ins ei Miseed ony eect) method is al instantly after the instance was created, ‘ances of this tp. Enterprise Java (T.Y.B.Sc.-I.T.) (Sem.-V) 1 68 ror ution : This method is called for every request of this JSP Breet gee ‘This is where it serves the purpose of creation. It has to pas through all the above steps to reach this phase. It passes the request and the response objects. jepService( ) method cannot be overridden. 7, jspDestroy( ) execution : This method is called when this JSP page is destroyed, With this call the Servlet serves its purpose and submits itself to garbage collection. This is the end of JSP life cycle. 12.5 HOW DOES A JSP FUNCTION? ] The web server needs a JSP engine, i.e, a container to process JSP pages. The JSP container is responsible for intercepting, requests for JSP pages. A JSP container works with the Web server to provide the runtime environment and other services a JSP needs. It knows how to understand the special elements that are part of JSPs. Following diagram shows the position of JSP container and JSP files in a Web application | HTML Handler handler forced on to HTML files, Process Java ISPTags || Compiter Runtime 12.6 How Does JSP Execute? The following steps explain how the web server creates the W © Aswith a normal page, your browser sends an HTTP req ° The = server recognizes that the HTTP request is for a 10 a JSP engine. This is d i to 2 JSP engine lone by using the URL or JSP p; @ The JSP engine loads the JSP is iti Lied tbarialerpadis 3s Page from disk and converts it into a servlet content are con} the corresponding dynamic behaviour eee od © The JSP engine compiles the servi original request to a serviet engine. © A part of the web server called the serviet i a ents Daring exccton the eves prdiy on Serle lass id ebpage using JSP ; uest to the web server. JSP page and forwards it age which ends with jsP et into an executable class and forwards the nee ree 89 ‘The output is furthur passed on to the web server by the servlet engine inside an HTTP response. @ The web server forwards the HTTP response to ‘your browser in terms of static HTML content. © Finally, the web browser handles the dynamically-generated HTML page inside the HTTP response exactly as if it were a static page. ‘Typically, the JSP engine checks to see whether a servlet for a JSP file already exists and whether the modification date on the JSP is older than the servlet. If the JSP is older than its generated servlet, the JSP container assumes that the JSP hasn't changed and that the generated servlet still matches the JSP's contents. This makes the process more efficient than with the other scripting languages (such as PHP) and therefore faster. So in a way, a JSP page is really just another way to write a servlet without having to be a Java programming wiz. Except for the translation phase, a JSP page is handled exactly like a regular servlet. 12.7 About Javaserver Pages 2.3 The JavaServer Pages (SP) 23 feature provides full support for the JSP 23 specification. Descriptions of the new JSP 2.3 functions are provided in the JSP 2.3 specification and are not described here. However, the new specification additions are minor, as compared to the JSP 2.2 feature : © Support for Expression Language (EL) 3.0 @ Availability of Servlet 3.1 APIs toa JSP. © There are no known behavior differences between JSP 2.2 and JSP 2.3 that directly prevent a JSP that runs with JSP 2.2 from successfully running with JSP 23. However, if a JSP uses Expression Language (EL) or Servlet API functions, you must consider the changes between Servlet 3.1 and Servlet 3.0, and between EL 3.0 and EL 2.2. QUESTIONS What is JSP? Explain its advantages and disadvantages. What are the advantages of JSP over technologies other than Servlet? Differentiate between Servlet and JSP. Explain the phases of JSP life cycle. Explain JSP functionality and execution. serene wae

You might also like