JavaBeans and JSP CS-422.

Slides:



Advertisements
Similar presentations
JSP and Servelets.
Advertisements

Apache Struts Technology
Chapter 81 JavaBeans JavaServer Pages By Xue Bai.
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
CS320 Web and Internet Programming Java Beans and Expression Language (EL) Chengyu Sun California State University, Los Angeles.
Java Beans & Serialization CS-328 Dick Steflik. Java Beans Java based component technology –originally developed to provide java with a component technology.
Internet Technologies 1 Master of Information System Management Java Server Faces Model/View/Controller Design Pattern for Web Development Slides.
DT228/3 Web Development Java Beans. Intro A major problem with JSP is tendency to mix java code with HTML  -  web designer write the HTML and programmer.
Object-Oriented Enterprise Application Development Lecture 8 Advanced JavaBeans.
Writing Enterprise Applications with J2EE (Fifth lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
Introducing JavaBeans Identify the features of a JavaBean Create and add a bean to an application Manipulate bean properties using accessor and mutator.
Java Server Pages CS-422. What are JSPs A logical evolution of java servlets –most servlets dynamically create HTML and integrate it with some computational.
Java Beans.
CSC 2720 Building Web Applications Using Java Beans, Custom Tags and Tag Libraries in JSP pages.
Using JavaBeans Components in JSP Documents. Contents 1. Why using beans? 2. What are beans? 3. Using Beans: Basic Tasks 4. Sharing Beans 5. Practice.
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
Introduction to JavaServer Pages (JSP) Slides from Dr. Mark Llewellyn.
Jordan Anastasiade. All rights reserved.
SWE 316: Software Design and Architecture Objectives Lecture # 19 Java Beans SWE 316: Software Design and Architecture  Understand  what JavaBeans (“Beans”)
© 2006 IBM Corporation IBM WebSphere Portlet Factory Architecture.
Chapter 8 Script-free pages. Problem with scripting in JSP When you use scripting (declaration, scriplet, expressions) in your JSP, you actually put Java.
Mark Dixon 1 12 – Java Beans. Mark Dixon 2 Session Aims & Objectives Aims –To cover the use of Java Beans Objectives, by end of this week’s sessions,
JavaBeans Components. To understand JavaBeans…  Proficient experience with the Java language required  Knowledge of classes and interfaces  Object-Oriented.
JAVA SERVER PAGES CREATING DYNAMIC WEB PAGES USING JAVA James Faeldon CS 119 Enterprise Systems Programming.
Webcommerce Computer Networks Webcommerce by Linnea Reppa Douglas Martindale Lev Shalevich.
CS320 Web and Internet Programming Java Beans and Expression Language (EL) Chengyu Sun California State University, Los Angeles.
Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 02 – Classes, Objects, Instances Richard Salomon and Umesh Patel Centre.
Java Bean Definition “A Java Bean is a reusable software component that can be manipulated visually in a builder tool.”
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
CSSE501 Object-Oriented Development. Chapter 4: Classes and Methods  Chapters 4 and 5 present two sides of OOP: Chapter 4 discusses the static, compile.
Java Server Pages Introduction. Servlet Drawbacks Web page designer will need to know servlets to design the page. Servlet will have to be compiled for.
CourseOutline Example & JavaBeans Lec Start with Example Displaying Course Outlines User will select either course “web design & development” or.
Chapter 5 Introduction to Defining Classes
Slides © Marty Hall, book © Sun Microsystems Press 1 Using JavaBeans with JSP Core Servlets & JSP book:
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
JAVA BEANS JSP - Standard Tag Library (JSTL) JAVA Enterprise Edition.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
Introduction to Software Components: the JavaBeans specs Babak Esfandiari.
JavaServer Faces framework Craig McClanahan is presented that created Struts web framework and based on experience gathered designed JavaServer.
CSI 3125, Preliminaries, page 1 JSP (Java Server Pages)
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,
Chapter 14 Using JavaBeans Components in JSP Documents.
Introduction to Server-Side Web Development Introduction to Server-Side Web Development Introduction to Server-Side Web JavaBeans; basic concepts and syntax.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Object Oriented Programming. Constructors  Constructors are like special methods that are called implicitly as soon as an object is instantiated (i.e.
JSP Action Elements Lec - 37.
JSP java server pages.
Structure of a web application
Phil Tayco Slide version 1.0 Created Sep 18, 2017
JSP (Java Server Page) JSP is server side technology which is used to create dynamic web pages just like Servlet technology. This is mainly used for implementing.
Scripted Page Web App Development (Java Server Pages)
Java Beans Sagun Dhakhwa.
Scope and State Handling in JSPs
Introduction to Java Bean
Introduction to Java Server Pages
Introduction to Java Bean
Java Server Pages (JSP)
CS320 Web and Internet Programming Java Beans
Class Everything if Java is in a class. The class has a constructor that creates the object. public class ClassName private Field data (instance variables)
CS3220 Web and Internet Programming Expression Language (EL)
CS3220 Web and Internet Programming Expression Language (EL)
Component-Based Software Engineering
Java Programming: Advanced Topics
Introduction to JSP Dept. of B.Voc Software Development and System Administration St. Joseph’s College(Autonomous) Trichy-02 By Dr. J. Ronald Martin Introduction.
Scripted Page Web Application Development (Java Server Pages)
Classes and Objects Systems Programming.
Presentation transcript:

JavaBeans and JSP CS-422

JavaBeans The Java component technology originally intended for the creation and management of “pluggable” GUI components; Java’s answer to Visual Basic’s VBX/OCXs becoming more popular for encapsulating business logic for server-side applications (especially Java Server Pages many Java GUI Development tools have been modified to allow application development of server-side applications (Visual Café, Jbuilder, VisualAge for Java) along with the development tools being delivered with application servers (SilverStream, BEA Weblogic) A JavaBean is nothing more than a class that maintains some state data (called properties) and follows a certain set of coding conventions. Along with certain Java runtime support (reflection and introspection) can JavaBeans can be easily added to and maintained by most of the Java GUI Development Tools .

API requires that: Must implement java.io.Serializable or java.io.Externalizable Beans must be able to support their own persistence this allows the bean to be saved and restored consistently provide a no-arguments constructor provides a single way for the Bean to be instantiated insures consistent bean creation and initialization private properties must have corresponding get/set methods that follow the appropriate naming patterns each piece of state data to be exposed is called a property made public via accessor and mutators (setters and getters) accessor methos names must start with “get” for property int color the accessor would be getcolor() mutator methods names must start with “set” for property fuelCapacity the mutator would be setfuelCapacity()

Environmental Support To use JavaBeans with JSP no environmental support is needed, but for a better understanding of JavaBeans in the whole we’ll take a look… Introspection ( java.beans.Introspector) defines the resources that allow the programatic construction of information on the Bean facilitates the discovery of properties and methods by inspecting the .class file can be done two ways : the reflection APIs or by providing a java.beans.BeanInfo class with the bean to describe the public methods and properties, Reflection (java.lang.reflect) a set of resources that allows a program to discover the public properties and methods of classes that have been loaded by the class loader this is facilitated by the naming convention for accessors and mutators (i.e. the names must start with “get” or “set”) don’t need to need to knownames of properties as long as we know the names of the accessor and mutators These environmental support mechanisma allow the JavaBeans to be cleanly integrated into GUI based, Java Development tools like VisualCafe, VisualAge and Jbuilder.

Example: a Stock bean import java.io.Serializable; public class Stock implements Serializable { Stock( ) { } // no argument constructor (just creates the object) private String name = null; private String tickerSymbol = null; private double tradingPrice = 0.0; private double sharesOwned = 0.0; public void setName(String n) { name = n; } public String getName( ) { return name;} public void setTickerSymbol( String s ) { tickerSymbol = s; } public String gettickerSymbol( ) { return tickerSymbol; } public void settradingPrice( double d ) { tradingPrice = d; } public double gettradingPrice( ) { return tradingPrice; } public void setsharesOwned( double v ) { sharesOwned = v; } public double getsharesOwned( ) { return sharesOwned; } }

jsp:useBean Tag jsp:useBean does the following: If the object is found within the specified scope it is retrieved and assigned to the object if not found it is instantiated if newly instantiated it executes the code specified in the body ( one or more jsp:setProperty tags or a scriptlet) if newly instantiated it is saved into the scope via setAttribute( ) method jsp:useBean also makes the bean visible to the JSP; there may be other objects in the context that were put there by other JSPs or servlets; jsp:useBean can make them visible to the current JSP

jsp:useBean Tag (more) Attributes : id scope class beanName type <jsp:useBean id = today class = “java.util.Date”> instantiates a bean called today of class java.util.Date( ) <jsp:useBean id = “count” class = “java.lang.Integer” type = “java.lang.Number”> essentially does : Number = count ; count = new Integer( ) <jsp:useBean id = “count” class = “<%= request.getParameter(“beanName”)%> type = “Number” /> essentiallt does: Number count; count = java.beans.Beans.instantiate(request.getParameter(“beanName”));

jsp:useBean Tag (more) In general the syntax is: <jsp:useBean id = “name” {scope = “page | request | session | application”} { class = “class name” | class = “class name” type = “type name” | beanName = “bean name” type = “type name” | type = “type name” } />