Jsp Presentation +Mufix "3"


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Jsp Presentation +Mufix "3"

  1. 1. Java Server Pages
  2. 2. Agenda <ul><li>CGI </li></ul><ul><li>Servlet </li></ul><ul><li>What is JSP ? </li></ul><ul><li>JSP Processing </li></ul><ul><li>JSP elements </li></ul><ul><li>How to use beans with JSP ? </li></ul>
  3. 3. Agenda <ul><li>CGI </li></ul><ul><li>Servlet </li></ul><ul><li>What is JSP ? </li></ul><ul><li>JSP Processing </li></ul><ul><li>JSP elements </li></ul><ul><li>How to use beans with JSP ? </li></ul>
  4. 4. CGI
  5. 5. Agenda <ul><li>CGI </li></ul><ul><li>Servlet </li></ul><ul><li>What is JSP ? </li></ul><ul><li>JSP Processing </li></ul><ul><li>JSP elements </li></ul><ul><li>How to use beans with JSP ? </li></ul>
  6. 6. Servlet <ul><li>Servlets are java programs that run on web servers. </li></ul><ul><li>Servlets have benefits that are platform independent , portable . </li></ul>
  7. 7. How Servlet works? Browser Web Server .java files Operating System Operating System HTTP Request HTML Servlet Engine Data Files JVM
  8. 8. Agenda <ul><li>CGI </li></ul><ul><li>Servlet </li></ul><ul><li>What is JSP ? </li></ul><ul><li>JSP Processing </li></ul><ul><li>JSP elements </li></ul><ul><li>How to use beans with JSP ? </li></ul>
  9. 9. What is JSP ? <ul><li>JavaServer Pages is a java-based technology for developing web pages that include dynamic content. </li></ul><ul><ul><ul><li>based on user input, time of day, or any other runtime conditions. </li></ul></ul></ul><ul><li>A JSP page is a HTML pages with JSP elements for generating the parts of the page that differ for each request. </li></ul>
  10. 10. Agenda <ul><li>CGI </li></ul><ul><li>Servlet </li></ul><ul><li>What is JSP ? </li></ul><ul><li>JSP Processing </li></ul><ul><li>JSP elements </li></ul><ul><li>How to use beans with JSP ? </li></ul>
  11. 11. JSP Processing
  12. 12. Agenda <ul><li>CGI </li></ul><ul><li>Servlet </li></ul><ul><li>What is JSP ? </li></ul><ul><li>JSP Processing </li></ul><ul><li>JSP elements </li></ul><ul><li>How to use beans with JSP ? </li></ul>
  13. 13. JSP Elements <ul><li>Comments </li></ul><ul><li>Scripting Elements </li></ul><ul><ul><ul><li>Scriptlets </li></ul></ul></ul><ul><ul><ul><li>Expressions </li></ul></ul></ul><ul><ul><ul><li>Declarations </li></ul></ul></ul><ul><li>Directives </li></ul><ul><li>Actions </li></ul>
  14. 14. JSP Comment <ul><li>HTML comment will appear in the output stream to the browser </li></ul><ul><ul><li><!-- comments … -- > </li></ul></ul><ul><li>JSP comment will not be processed by the JSP compiler </li></ul><ul><ul><li><%-- comments … --%> </li></ul></ul>
  15. 15. Scripting Elements <ul><ul><li>Scriptlets </li></ul></ul><ul><ul><li>Expressions </li></ul></ul><ul><ul><li>Declarations </li></ul></ul>
  16. 16. <% Scriptlets %> <ul><li>A Scriptlet element is simply a section of Java code encapsulated within the opening and closing standard JSP tags . </li></ul><ul><li>JSP Syntax: </li></ul><ul><li><% code %> </li></ul>
  17. 17. <% Example %>
  18. 18. <%= Expressions %> <ul><li>An Expression element is a Java language expression whose value is evaluated and returned as a string to the page. </li></ul><ul><li>JSP Syntax: </li></ul><ul><li><%= code %> </li></ul>
  19. 19. <%= Example %>
  20. 20. <%! Declarations %> <ul><li>A Declaration element is used to declare methods and variables that are initialized with the page. </li></ul><ul><li>JSP Syntax: </li></ul><ul><li><%! code %> </li></ul>
  21. 21. <%! Example %>
  22. 22. Directives <ul><li>JSP directives are used to send messages to the JSP engine. </li></ul><ul><li>Directives general syntax </li></ul><ul><ul><ul><li><%@ directive attribute=“value”%> </li></ul></ul></ul><ul><ul><ul><ul><ul><li>The Page Directive </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>The Include Directive </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>The Taglib Directive </li></ul></ul></ul></ul></ul>
  23. 23. <%@ Page %> <ul><li>Used for importing classes and setting up content type. </li></ul><ul><li>EX: </li></ul><ul><ul><ul><li>imports the java.utilCalendar class </li></ul></ul></ul><ul><ul><ul><ul><ul><li><%@ page import=&quot;java.util.Calendar&quot; %> </li></ul></ul></ul></ul></ul><ul><ul><ul><li>sets the contentType </li></ul></ul></ul><ul><ul><ul><ul><ul><li><%@ page contentType=&quot;text/html&quot; %> </li></ul></ul></ul></ul></ul>
  24. 24. <%@ include %> <ul><li>Used for inserting a file to the servlet when the JSP page is translated to a servlet. </li></ul><ul><li>EX: </li></ul><ul><ul><ul><li><%@ include file=&quot;footer.jsp&quot; %> </li></ul></ul></ul><ul><ul><ul><li><%@include file = &quot;/products/examples/listing.html&quot; %> </li></ul></ul></ul>
  25. 25. <%@ Taglib %> <ul><li>It tells the JSP engine that this JSP page uses a tag library. </li></ul><ul><li>It specifies the location of a special jar file containing a Tag Library Descriptor. </li></ul><ul><li>EX: </li></ul><ul><ul><ul><li><%@ taglib uri=&quot; http://www.javadesktop.com/sampletags.jar &quot; </li></ul></ul></ul><ul><li>prefix=&quot; sample &quot; %> </li></ul><ul><ul><ul><li><sample:tagAction> This is an example </sample:tagAction> </li></ul></ul></ul>
  26. 26. Actions <ul><li>Ex: </li></ul><ul><ul><ul><li><jsp:useBean> imports a JavaBeans component. </li></ul></ul></ul><ul><ul><ul><li><jsp:getProperty> gets a property value and adds it to the response. </li></ul></ul></ul><ul><ul><ul><li><jsp:setProperty> sets a property value. </li></ul></ul></ul>
  27. 27. Agenda <ul><li>CGI </li></ul><ul><li>Servlet </li></ul><ul><li>What is JSP ? </li></ul><ul><li>JSP Processing </li></ul><ul><li>JSP elements </li></ul><ul><li>How to use beans with JSP ? </li></ul>
  28. 28. What Is a Bean? <ul><li>JavaBeans are regular Java classes designed according to the set of guidelines </li></ul><ul><li>defined by the JavaBeans specification </li></ul>
  29. 29. Bean properties <ul><li>A bean class must have a no-argument constructor. </li></ul><ul><li>The bean class should implement the java.io.Serializable . </li></ul><ul><li>Data held by a bean is referred to as the bean's properties . </li></ul><ul><li>The property name is case-sensitive and always starts with a lowercase letter. </li></ul><ul><li>A property is either read-only, write-only or read/write, and has a value corresponding to a specific Java data type (for instance String,java.util.Date, or int ) . </li></ul>
  30. 30. Bean properties Cont. <ul><li>The bean properties are accessed through ( accessor methods ) getter and setter methods. </li></ul><ul><li>Getter and setter method names are composed of the word get or set , respectively, plus the property name, with the first character of each word capitalized. </li></ul><ul><li>A getter method has no arguments and returns a value of the property's type, while </li></ul><ul><li>a setter method takes a single argument of the property's type and has a void return type. </li></ul>
  31. 31. Bean Example
  32. 32. Declaring a Bean in a JSP Page ? <ul><li>Before you use a bean in a page, you must tell the JSP container which type of bean it is and associate it with a name: in other words, you must declare the bean. </li></ul>
  33. 33. basic tags for working with Beans <ul><li>JSP provide three basic tags for working with Beans : </li></ul><ul><ul><ul><ul><li><jsp:useBean > </li></ul></ul></ul></ul><ul><ul><ul><ul><li><jsp:setProperty > </li></ul></ul></ul></ul><ul><ul><ul><ul><li><jsp:getProperty > </li></ul></ul></ul></ul><ul><li>These three tags are JSP standard actions. </li></ul>
  34. 34. <jsp:useBean > <ul><li><jsp:useBean id =“ bean name ” class =“bean class”/> </li></ul><ul><li>EX: </li></ul><ul><ul><ul><li><jsp:useBean id=&quot;cartoon&quot; class=&quot;com.ora.jsp.beans.motd.CartoonBean&quot; /> </li></ul></ul></ul>
  35. 35. <jsp:setProperty > <ul><li><jsp:setProperty name = “id” property =“someProperty” value =“someValue”/> </li></ul><ul><ul><ul><ul><li>id = the name of the bean as specified in the useBean tag. </li></ul></ul></ul></ul><ul><ul><ul><ul><li>property = name of the property to be passed to the bean. </li></ul></ul></ul></ul><ul><ul><ul><ul><li>value = value of that particular property </li></ul></ul></ul></ul><ul><li>EX : </li></ul><ul><ul><ul><li><jsp:setProperty name=&quot; cartoon &quot; property=&quot; fileName“ value=“Books&quot; /> </li></ul></ul></ul>
  36. 36. <jsp:getProperty > <ul><li><jsp:getProperty name = “id” property = “someProperty” /> </li></ul><ul><li>This action obtains the current value of a bean property and inserts it directly into the response body. </li></ul><ul><li>EX: </li></ul><ul><ul><ul><li><jsp:getProperty name=&quot;cartoon&quot; property=&quot;fileName&quot; /> </li></ul></ul></ul>
  37. 37. Example
  38. 38. <ul><li>Demos </li></ul>
  39. 39. Question ?