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