JavaServer Pages

986 views

Published on

JavaServer Pages enable Web developers and designers to rapidly develop and easily maintain, information-rich, dynamic Web pages that leverage existing business systems.
www.silenceit.ca

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
986
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

JavaServer Pages

  1. 1. Java Server Pages<br />JSP, JSTL, and Servlets<br />
  2. 2. Topics<br />What is JSP<br />What is JSTL<br />What is a Servlet?<br />What are Beans?<br />JSP Access Models<br />Benefits and Shortcomings<br />Samples<br />Questions / Comments<br />
  3. 3. What is JSP?<br />JavaServer Pages enable Web developers and designers to rapidly develop and easily maintain, information-rich, dynamic Web pages that leverage existing business systems.<br />JSP technology enables development of Web-based applications that are platform independent.<br />JSP technology separates the user interface from content generation, enabling designers to easily change the overall page layout without altering the underlying dynamic content.<br />
  4. 4. What is JSTL?<br />The JavaServer Pages Standard Tag Library (JSTL) encapsulates core functionality common to many web applications. single, standard set of tags.<br />JSTL has support for common, structural tasks such as iteration and conditionals, tags for manipulating XML documents, internationalization tags, and SQL tags.<br />Examples:<br />1:<br />&lt;c:forEach var=&quot;item“ items=&quot;${sessionScope.cart.items}&quot;&gt; <br /> &lt;tr&gt;&lt;td&gt;<br /> &lt;c:out value=“${item.name}”&gt;&lt;/td&gt;<br /> &lt;td&gt;&lt;c:out value=“${item.price}”&gt;<br /> &lt;/td&gt;&lt;/tr&gt;<br />&lt;/c:forEach&gt;<br />2:<br />&lt;c:choose&gt;<br /> &lt;c:when test=&apos;${param.responseText == “Fail&quot;}&apos;&gt; &lt;b&gt;There was an error!&lt;/b&gt;<br /> &lt;/c:when&gt;<br /> &lt;c:otherwise&gt;<br /> Everything is great!<br /> &lt;/c:otherwise&gt; <br />&lt;/c:choose&gt;<br />
  5. 5. What is a Servlet?<br />Java Servlet technology provides Web developers with a simple, consistent mechanism for extending the functionality of a Web server and for accessing existing business systems<br />A servlet can almost be thought of as an applet that runs on the server side--without a face. <br />Servlets have access to the entire family of Java APIs, including the JDBC API to access enterprise databases.<br />Servlets can also access a library of HTTP-specific calls and receive all the benefits of the mature Java language, including portability, performance, reusability, and crash protection.<br />Servlet:<br />package silenceit;public class Hello{  public String show(){    return ”Hello”;  }}<br />JSP Page:<br />&lt;%@page import=“silenceit.hello&quot; %&gt;<br />&lt;html&gt;<br /> &lt;head&gt;<br /> &lt;title&gt;<br /> Example of page Directive in JSP<br /> &lt;/title&gt;<br /> &lt;/head&gt;<br /> &lt;body&gt;<br /> &lt;% <br /> Hello he = new Hello();<br />out.print(he.show()); <br /> %&gt;<br /> &lt;/body&gt;<br />&lt;/html&gt;<br />
  6. 6. What are Beans?<br />Java Beans are reusable components. They are used to separate Business logic from the Presentation logic. Internally, a bean is just an instance of a class with special naming conventions and characteristics.<br />Bean Conventions:<br />In order to function as a JavaBean class, an object class must obey certain conventions about method naming, construction, and behavior. These conventions make it possible to have tools that can use, reuse, replace, and connect JavaBeans.<br />The class must have a public default constructor. This allows easy instantiation within editing and activation frameworks.<br />The class properties must be accessible using get, set, and other methods (so-called accessor methods and mutator methods), following a standard naming convention. This allows easy automated inspection and updating of bean state within frameworks, many of which include custom editors for various types of properties.<br />The class should be serializable. This allows applications and frameworks to reliably save, store, and restore the bean&apos;s state in a fashion that is independent of the VM and platform.<br />Example Bean:<br />publicclassPersonBeanimplementsjava.io.Serializable {<br /> private String name;<br /> privateboolean deceased; <br /> /** No-arg constructor*/<br /> publicPersonBean() {<br /> } <br /> /** * Property */<br /> public String getName() {<br />returnthis.name;<br /> } <br /> /** * Setter for property Name */<br />publicvoidsetName(final String name) {<br /> this.name = name;<br /> }<br /> /** * Getter for property &quot;deceased&quot; * Different syntax for a boolean field (is vs. get) */<br /> publicbooleanisDeceased() {<br /> returnthis.deceased;<br /> }<br /> /** * Setter for property deceased */<br />publicvoidsetDeceased(finalboolean deceased) { <br />this.deceased = deceased;<br /> }<br />}<br />
  7. 7. JSP Access Models<br />The early JSP specifications advocated two philosophical approaches, popularly known as Model 1 and Model 2 architectures, for applying JSP technology. These approaches differ essentially in the location at which the bulk of the request processing is performed<br />Model 1<br />Model 2<br />The Model 2 architecture, shown above, is a server-side implementation of the popular Model/View/Controller design pattern. Here, the processing is divided between presentation and front components. Presentation components are JSP pages that generate the HTML/XML response that determines the user interface when rendered by the browser. Front components (also known as controllers) do not handle any presentation issues, but rather, process all the HTTP requests<br />Although the Model 1 architecture is suitable for simple applications, it may not be desirable for complex implementations. Indiscriminate usage of this architecture usually leads to a significant amount of scriptlets or Java code embedded within the JSP page<br />
  8. 8. Benefits and Shortcomings<br />JSP Benefits:<br />Platform and Server Independence<br />Open Development Process, Open Source<br />Extensible JSP Tags<br />Application persistence and variable scopes<br />Mature Java language<br />Easier Maintenance<br />Scripting languages are fine for small applications, but do not scale well to manage large, complex applications. Because the Java language is structured, it is easier to build and maintain large, modular applications with it.<br />JSP technology&apos;s emphasis on components over scripting makes it easier to revise content without affecting logic, or revise logic without changing content.<br />The Enterprise JavaBeans architecture encapsulates the enterprise logic, such as database access, security, and transaction integrity, and isolates it from the application itself.<br />Because JSP technology is an open, cross-platform architecture, Web servers, platforms, and other components can be easily upgraded or switched without affecting JSP-based applications. This makes JSP suitable for real-world Web applications, where constant change and growth is the norm.<br />Security<br />Since JSP can interoperate with standard Java it has access to the underlying Java SE Platforms extensible security architecture .<br />Security features — cryptography, authentication and authorization, public key infrastructure, and more.<br />JSP Shortcomings:<br /><ul><li>Compiler Required
  9. 9. JSP Typically issues poor error reports
  10. 10. JSP Pages use more disk space then regular scripting languages
  11. 11. Need a solid knowledge of Java
  12. 12. Some simple tasks are more difficult to perform
  13. 13. Coding standards need to be diligently adhered to
  14. 14. Since java programs run in the Java Virtual Machine, they run somewhat slower then applications written in C or C++</li></li></ul><li>Samples<br />Pizzapizza.com - Food<br />Tdcanadatrust.com - Banking<br />Americancentury.com - Investments<br />Sportsauthority.com - News<br />Imagechef.com - Fun<br />Stjohns.ca - Government<br />

×