Chapter 81 JavaBeans JavaServer Pages By Xue Bai.

Slides:



Advertisements
Similar presentations
Chapter 22 Implementing lists: linked implementations.
Advertisements

8 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: JavaServer Pages.
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
OO Programming Objectives for today: Casting Objects Introduction to Vectors The instanceof keyword.
5-May-15 ArrayLists. 2 ArrayList s and arrays A ArrayList is like an array of Object s Differences between arrays and ArrayList s: Arrays have special.
Chapter 51 Scripting With JSP Elements JavaServer Pages By Xue Bai.
Chapter 31 Basic Form-Processing Techniques JavaServer Pages By Xue Bai.
L2. Necessary Java Programming Techniques (Vector) Packages  Java.util import Java.util.*; Classes  Vector Interfaces  Enumeration Java API.
Using JavaServer Pages Harry R. Erwin, PhD CIT304/CSE301.
JSP: JavaServer Pages Juan Cruz Kevin Hessels Ian Moon.
For use of Cleveland State's IST410 Students only 1 Vectors and Collections.
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.
COMP201 Java Programming Part III: Advanced Features Topic 16: JavaServer Pages (JSP) Servlets and JavaServer Pages (JSP) 1.0: A Tutorial
25-Jun-15 Vectors. 2 Vectors and arrays A Vector is like an array of Object s Differences between arrays and Vector s: Arrays have special syntax; Vector.
Java Server Pages Russell Beale. What are Java Server Pages? Separates content from presentation Good to use when lots of HTML to be presented to user,
ASP.NET Programming with C# and SQL Server First Edition
Introduction to Server-Side Web Development Introduction to Server-Side Web Development JSP Final Remarks 10 th March 2005 Bogdan L. Vrusias
Java Enterprise Edition Java Web Development Structure of a web project Introduction to Web Applications The first project Introduction to Java Web Development.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 9 JavaServer Pages (JSP) (Based on Møller.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
CSC 2720 Building Web Applications Using Java Beans, Custom Tags and Tag Libraries in JSP pages.
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.
JSP Java Server Pages Softsmith Infotech.
Introduction to JavaServer Pages (JSP) Slides from Dr. Mark Llewellyn.
Jordan Anastasiade. All rights reserved.
CSCI 6962: Server-side Design and Programming Introduction to Java Server Faces.
Chapter 8 Script-free pages. Problem with scripting in JSP When you use scripting (declaration, scriplet, expressions) in your JSP, you actually put Java.
CSCI 6962: Server-side Design and Programming Java Server Faces Components and Tags.
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,
04/29/ Introduction to Vectors?... A vector is a dynamic array. - It can be expanded and shrunk as required - A Component of a vector can be accessed.
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
Generalized Containers CSIS 3701: Advanced Object Oriented Programming.
JAVA SERVER PAGES CREATING DYNAMIC WEB PAGES USING JAVA James Faeldon CS 119 Enterprise Systems Programming.
JSTL, XML and XSLT An introduction to JSP Standard Tag Library and XML/XSLT transformation for Web layout.
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
Data Structures Using Java1 Chapter 2 Inheritance and Exception Handling.
JavaServer Page by Antonio Ko. Overview ► Introduction ► What is a servlet? ► What can servlets do? ► Servlets Vs JSP ► Syntax ► Samples ► JavaBean ►
Java Beans. Definitions A reusable software component that can be manipulated visually in a ‘builder tool’. (from JavaBean Specification) The JavaBeans.
CourseOutline Example & JavaBeans Lec Start with Example Displaying Course Outlines User will select either course “web design & development” or.
CSCI 6962: Server-side Design and Programming JSF DataTables and Shopping Carts.
1 Chapter 5: Defining Classes. 2 Basics of Classes An object is a member of a class type What is a class? Fields & Methods Types of variables: –Instance:
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.
© 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.
STRUCTURE OF JSP PRESENTED BY: SIDDHARTHA SINGH ( ) SOMYA SHRIVASTAV ( ) SONAM JINDAL ( )
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 43 JavaServer Page.
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.
Chapter 6 Chapter 6 Server Side Programming (JSP) Part 1 1 (IS 203) WebProgramming (IS 203) Web Programming.
 Java Server Pages (JSP) By Offir Golan. What is JSP?  A technology that allows for the creation of dynamically generated web pages based on HTML, XML,
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Chapter 14 Using JavaBeans Components in JSP Documents.
19-Mar-16 Collections and ArrayLists.. 2 Collections Why use Collections. Collections and Object-Orientation. ArrayLists. Special Features. Creating ArrayLists.
JSP Java Server Pages. Hello, !
Introduction to Server-Side Web Development Introduction to Server-Side Web Development Introduction to Server-Side Web JavaBeans; basic concepts and syntax.
Web Database Programming Using PHP
JSP java server pages.
3 Introduction to Classes and Objects.
Web Database Programming Using PHP
Scripted Page Web App Development (Java Server Pages)
JavaBeans and JSP CS-422.
The Vector Class An object of class Vector is similar to an array in that it stores multiple values However, a vector only stores objects does not have.
Programming II (CS300) Chapter 02: Using Objects Java ArrayList Class
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)
Presentation transcript:

Chapter 81 JavaBeans JavaServer Pages By Xue Bai

Chapter 82 Objectives In this chapter, you will: Survey the basics of the Java programming language Write JavaBeans Compile and install bean classes Use beans with action tags Get and set bean’s properties Connect beans with forms Use beans in scriptlets Write a file bean to read from and write to files

Chapter 83 Java Primer JavaBeans are written in Java JSP uses the same syntax as Java programming language JSP is built on top of servlet, which in turn is built on Java

Chapter 84 Objects and Classes A class is a template or blueprint for objects A class consists of three parts: –Data members –Methods –Constructors Objects are instances of classes

Chapter 85 Class Example public class Circle{ private float radius; private float area; public Circle(){ radius=0.0f; area = 0.0f; } public Circle(float radius){ this.radius = radius; area = 0.0f; } public void setRadius(float radius){ this.radius = radius; } public void calculateArea(){ area = radius*Math.PI; } public float getArea(){ return area;} }

Chapter 86 Vector One of the most frequently used classes in Java Create Vector object: –Vector v1 = new Vector(); –Vector v2 = new Vector(Collection c); –Vector v3 = new Vector(int initialCapacity); –Vector v4 = new Vector(int initialCapacity, int increments);

Chapter 87 MethodUsage addElement(Object o) or add(Object o) Appends the specified object in the argument to the end of the vector. elementAt(int index)Returns the component at the specified index. The index of the first element is zero, the second one is 1, and so on. Contains(Object o)Tests whether the specified object is a component in this vector. It returns a Boolean value indexOf(object o)Searches for the first occurrence of the given argument, testing for equality using the equals method. It returns the index of the element in the vector if found, -1 otherwise. InsertElementAt(Object o, int index) Inserts the specified object as a component in this vector at the specified index size()Returns the number of components in this vector as an int

Chapter 88 Using Vector Storing objects Vector v = new Vector(); v.addElement(“Lynne”); Retrieving object: Object obj = v.elementAt(0); Cast object to its original data type: String s = (String)obj;

Chapter 89 Writing JavaBean Reusable components in JSP Written in Java Regular Java classes with certain rules: –Rules for GET and SET methods: –If a data member is called foo, then its GET and SET methods as follow: getFoo(); setFoo(“arguments”);

Chapter 810 Class Example package com.jspbook.chapter08; public class SimpleBean{ private String message; public SimpleBean(){ message = "Hi, there."; } public String getMessage(){ return message;} public void setMessage(String aMessage){ message = aMessage;} }

Chapter 811 Installing Bean Classes A directory the JSP engine looks for in the classpath One choice in Tomcat is: –TomatRoot\WEB-INF\classes

Chapter 812 Using Beans With action tags, you can use these beans No Java programming language is required in order to use beans With simple action tags, you can utilize all Java powerful features in JSP: –Perform I/O –Use well-fined collection classes, etc.

Chapter 813 Instantiate a Bean Object Create and load a JavaBean “bean_name” is the name that refers to the bean It must be unique everywhere it is to be used No two beans can have the same name in the same page The bean name serves as a local variable reference to the bean object

Chapter 814 Accessing Bean Properties This tag retrieves the value of a bean property, converts it to a string, and inserts it into the output The two required attributes are name and property The “bean name” is the same name specified in the ID attribute when the bean is created, and the “property name” is the name of the property to get

Chapter 815 Set Bean Properties This tag assigns a new value to the specified property In this tag, the “value” attribute specifies the new value to be assigned to the bean property

Chapter 816 Setting a Bean Property Form

Chapter 817 Setting a Bean Property

Chapter 818 Beans and Forms Beans interact with forms to generate dynamic Web pages Use form control elements to interact with bean properties

Chapter 819 Setting Properties with form Input Fields The value assigned to the property is presumed to come from the form In order for this technique to work, the bean must have a public setter method called setFoo, and this method takes a String object as an argument This tag requires the match between the property name and the form’s input parameter name

Chapter 820 Setting Properties with form Input Fields Used when the name of the form parameter and the name of the property do not match This tag uses the form input field called “inputFieldName” to set the bean’s property called “propertyName”

Chapter 821 Setting Properties with Form Input Fields Looks through all the input fields provided by the form and all the methods provided by the bean, and links them together automatically

Chapter 822 Working with Arrays Multiple values are associated with one input field You can also use a bean to get all these values associated with the same input field on a form

Chapter 823 A SETTER Method Taking Array Argument public void setValues(String[] values){ this.values = values; }

Chapter 824 Beans and Scriptlet locates or instantiates a bean object from the class and binds the variable specified as “bean_name” to the bean object After the variable “bean_name” has been bound to the bean object, you can use this variable as a reference to the bean object in your JSP script Since the variable is a reference to the bean object, you can call all methods provided by the bean in your JSP scriptlets

Chapter 825 Beans and Scriptlets Example <% calcBean.setValue1(request.getParameter("value1")); calcBean.setValue2(request.getParameter("value2")); %>

Chapter 826 A Bean performs I/O Write JavaBean class to perform I/O Use Bean in JSP

Chapter 827 Bulletin Board

Chapter 828 Posting a Bulletin

Chapter 829 Saving the Bulletin

Chapter 830 Viewing the Bulletin