SlideShare a Scribd company logo
Java Beans
Agenda
• Understanding the benefits of beans
• Creating beans
• Installing beans classes on server
• Accessing bean properties
What is JavaBean
• JavaBean is reusable software components
• Rules for creating Java Bean
- Public class
- Private/protected instance variable
- Zero-arg constructor
- Public getter and setter methods(accessor and mutator )
• Any java class which satisfies the above rule is a Java Bean
Why use a JavaBeans Component
• A JSP page can create and use any type of Java programming language object within a declaration or
scriptlet. The following scriptlet creates the bookstore shopping cart and stores it as a session attribute:
- <% ShoppingCart cart = (ShoppingCart)session. getAttribute("cart"); // If the user has no
cart, create a new one if (cart == null) { cart = new ShoppingCart();
session.setAttribute("cart", cart); } %>
• If the shopping cart object conforms to JavaBeans conventions, JSP pages can use JSP elements to
create and access the object. For example, the Duke's Bookstore pages bookdetails.jsp, catalog.jsp, and
showcart.jsp replace the scriptlet with the much more concise JSP useBean element:
<jsp:useBean id="beanName" class="fully_qualified_classname" scope="scope"/>
Or
<jsp:useBean id="beanName" class="fully_qualified_classname“
scope="scope"> <jsp:setProperty /> </jsp:useBean>
Types of properties
• Simple Properties
- private String name
• Indexed properties
- private String[] skills
• Boolean properties
- private boolean experienced
How to access javabean in JSP
• <jsp:useBean> action
- Enables JSP to manipulate Java object
• Creates Java object or locates an existing object for use in JSP
• Location can be
- Page Scope
- Request Scope
- Session Scope
- Application Scope
<jsp:useBean> attributes
Attribute Description
id The name used to manipulate the Java object with actions
<jsp:setProperty> and <jsp:getProperty>. A variable of
this name is also declared for use in JSP scripting elements. The name
specified here is case sensitive.
scope The scope in which the Java object is accessible—page, request,
session or application. The default scope is page.
class The fully qualified class name of the Java object.
beanName The name of a bean that can be used with method instantiate of
class java.beans.Beans to load a JavaBean into memory.
type The type of the JavaBean. This can be the same type as the class
attribute, a superclass of that type or an interface implemented by that
type. The default value is the same as for attribute class. A
ClassCastException occurs if the Java object is not of the type
specified with attribute type.
<jsp:useBean> attributes( cont)
Attribute Description
name The ID of the JavaBean for which a property (or properties) will be
set.
property The name of the property to set. Specifying "*"for this attribute
causes the JSP to match the request parameters to the properties of the
bean.For each request parameter that matches (i.e., the name of the
request parameter is identical to the bean’s property name), the
corresponding property in the bean is set to the value of the parameter.
If the value of the request parameter is"", the property value in the
bean remains unchanged.
param If request parameter names do not match bean property names, this
attribute can be used to specify which request parameter should be
used to obtain the value for a specific bean property. This attribute is
optional. If this attribute is omitted, the request parameter names must
match bean property names.
value The value to assign to a bean property. The value typically is the result
of a JSP expression. This attribute is particularly useful for setting
bean properties that cannot be set using request parameters. This
attribute is optional. If this attribute is omitted, the JavaBean property
must be of a type that can be set using request parameters.
Fig. 25.16 Attributes of the <jsp:setProperty> action.
JavaBean Example
package mypack;
public class Student {
private String name;
private int rollno;
public Student(){}
public Student(String name, int rollno) {
this.name = name;
this.rollno = rollno; }
public String getName() { return name; }
public void setName(String name) {this.name = name; }
public int getRollno() { return rollno; }
public void setRollno(int rollno) { this.rollno = rollno; }
}
Setting the properties
<jsp:useBean id=“student" class=“mypack.Student" scope="session">
<jsp:setProperty name=“student" property=“name“ value=“king” />
<jsp:setProperty name=“student” property=“rollno” value=“21” />
</jsp:useBean>
1. beanName must be the same as that specified for the id
attribute in a useBean element.
2. There must be a setPropName method in the JavaBeans
component.
3. paramName must be a request parameter name.
Setting the properties
Value Source Element Syntax
String constant
<jsp:setProperty name="beanName"
property="propName" value="string constant"/>
Request parameter
<jsp:setProperty name="beanName"
property="propName" param="paramName"/>
Request parameter name matches
bean property
<jsp:setProperty name="beanName"
property="propName"/>
<jsp:setProperty name="beanName"
property="*"/>
Expression
<jsp:setProperty name="beanName"
property="propName"
value="<%= expression %>"/>
Accessing javaBean in jsp
<html>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<body>
<jsp:useBean id="s" class="mypack.Student" scope="session">
<jsp:setProperty name="s" property="name" value="ma ma"/>
<jsp:setProperty name="s" property="rollno" value="1"/>
</jsp:useBean>
<jsp:getProperty name="s" property=“name”/>
<jsp:getProperty name="s" property="rollno"/>
</body>
</html>
Advantages of JavaBean
• “Write once run anywhere”
• Reusable Components
• Seperation of Business logic from Presentation and Navigation
• Loosely Coupled
• EJB can also be used for business logic
• No need to implement any API for creating a JavaBean
• Using reflection can access properties, method easily dynamically
Summary
• JavaBean is a specification
• Simple convention for creating JavaBean
• Best Practises
• Standard action to create and access the JavaBean
• Standard action to read their content
• EL can also be used to access the properties

More Related Content

What's hot

Implicit object.pptx
Implicit object.pptxImplicit object.pptx
Implicit object.pptx
chakrapani tripathi
 
Java beans
Java beansJava beans
Java beans
sptatslide
 
Introduction to java beans
Introduction to java beansIntroduction to java beans
Introduction to java beans
Hitesh Parmar
 
Implicit objects advance Java
Implicit objects advance JavaImplicit objects advance Java
Implicit objects advance Java
Darshit Metaliya
 
Jsp quick reference card
Jsp quick reference cardJsp quick reference card
Jsp quick reference card
JavaEE Trainers
 
Hibernate
HibernateHibernate
Hibernate
Leonardo Passos
 
Javabeans
JavabeansJavabeans
Javabeans
vamsitricks
 
Java Web Programming [7/9] : Struts2 Basics
Java Web Programming [7/9] : Struts2 BasicsJava Web Programming [7/9] : Struts2 Basics
Java Web Programming [7/9] : Struts2 Basics
IMC Institute
 
Service Oriented Architecture -Unit II - Modeling databases in xml
Service Oriented Architecture -Unit II - Modeling databases in xml Service Oriented Architecture -Unit II - Modeling databases in xml
Service Oriented Architecture -Unit II - Modeling databases in xml
Roselin Mary S
 
Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2
Fahad Golra
 
Jsf
JsfJsf
Java component
Java componentJava component
Java component
krishashi
 
Jsp presentation
Jsp presentationJsp presentation
Jsp presentation
Sher Singh Bardhan
 
Javabeans .pdf
Javabeans .pdfJavabeans .pdf
Javabeans .pdf
Rajkiran Mummadi
 
3.jsp tutorial
3.jsp tutorial3.jsp tutorial
3.jsp tutorial
shiva404
 
A Dexterity Intro for Recovering Archetypes Addicts
A Dexterity Intro for Recovering Archetypes AddictsA Dexterity Intro for Recovering Archetypes Addicts
A Dexterity Intro for Recovering Archetypes Addicts
David Glick
 
Hibernate
HibernateHibernate
Hibernate
Prashant Kalkar
 
RequireJS & Handlebars
RequireJS & HandlebarsRequireJS & Handlebars
RequireJS & Handlebars
Ivano Malavolta
 
Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1
Michał Orman
 
Jsp Introduction Tutorial
Jsp Introduction TutorialJsp Introduction Tutorial
Jsp Introduction Tutorial
APSMIND TECHNOLOGY PVT LTD.
 

What's hot (20)

Implicit object.pptx
Implicit object.pptxImplicit object.pptx
Implicit object.pptx
 
Java beans
Java beansJava beans
Java beans
 
Introduction to java beans
Introduction to java beansIntroduction to java beans
Introduction to java beans
 
Implicit objects advance Java
Implicit objects advance JavaImplicit objects advance Java
Implicit objects advance Java
 
Jsp quick reference card
Jsp quick reference cardJsp quick reference card
Jsp quick reference card
 
Hibernate
HibernateHibernate
Hibernate
 
Javabeans
JavabeansJavabeans
Javabeans
 
Java Web Programming [7/9] : Struts2 Basics
Java Web Programming [7/9] : Struts2 BasicsJava Web Programming [7/9] : Struts2 Basics
Java Web Programming [7/9] : Struts2 Basics
 
Service Oriented Architecture -Unit II - Modeling databases in xml
Service Oriented Architecture -Unit II - Modeling databases in xml Service Oriented Architecture -Unit II - Modeling databases in xml
Service Oriented Architecture -Unit II - Modeling databases in xml
 
Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2
 
Jsf
JsfJsf
Jsf
 
Java component
Java componentJava component
Java component
 
Jsp presentation
Jsp presentationJsp presentation
Jsp presentation
 
Javabeans .pdf
Javabeans .pdfJavabeans .pdf
Javabeans .pdf
 
3.jsp tutorial
3.jsp tutorial3.jsp tutorial
3.jsp tutorial
 
A Dexterity Intro for Recovering Archetypes Addicts
A Dexterity Intro for Recovering Archetypes AddictsA Dexterity Intro for Recovering Archetypes Addicts
A Dexterity Intro for Recovering Archetypes Addicts
 
Hibernate
HibernateHibernate
Hibernate
 
RequireJS & Handlebars
RequireJS & HandlebarsRequireJS & Handlebars
RequireJS & Handlebars
 
Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1
 
Jsp Introduction Tutorial
Jsp Introduction TutorialJsp Introduction Tutorial
Jsp Introduction Tutorial
 

Similar to Advance java session 12

Using java beans(ii)
Using java beans(ii)Using java beans(ii)
Using java beans(ii)
Ximentita Hernandez
 
Jsp
JspJsp
Java Beans
Java BeansJava Beans
Java Beans
Ankit Desai
 
Java Beans Unit 4(Part 1)
Java Beans Unit 4(Part 1)Java Beans Unit 4(Part 1)
Java Beans Unit 4(Part 1)
SURBHI SAROHA
 
KMUTNB - Internet Programming 5/7
KMUTNB - Internet Programming 5/7KMUTNB - Internet Programming 5/7
KMUTNB - Internet Programming 5/7
phuphax
 
KMUTNB - Internet Programming 5/7
KMUTNB - Internet Programming 5/7KMUTNB - Internet Programming 5/7
KMUTNB - Internet Programming 5/7
phuphax
 
ADP - Chapter 5 Exploring JavaServer Pages Technology
ADP - Chapter 5 Exploring JavaServer Pages TechnologyADP - Chapter 5 Exploring JavaServer Pages Technology
ADP - Chapter 5 Exploring JavaServer Pages Technology
Riza Nurman
 
Intro To Sap Netweaver Java
Intro To Sap Netweaver JavaIntro To Sap Netweaver Java
Intro To Sap Netweaver Java
Leland Bartlett
 
Jpa queries
Jpa queriesJpa queries
Jpa queries
gedoplan
 
Jsp session 5
Jsp   session 5Jsp   session 5
Jsp session 5
Anuj Singh Rajput
 
java beans
java beansjava beans
java beans
lapa
 
Session 44 - Spring - Part 2 - Autowiring, Annotations, Java based Configuration
Session 44 - Spring - Part 2 - Autowiring, Annotations, Java based ConfigurationSession 44 - Spring - Part 2 - Autowiring, Annotations, Java based Configuration
Session 44 - Spring - Part 2 - Autowiring, Annotations, Java based Configuration
PawanMM
 
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slidesSpring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
Hitesh-Java
 
Jsp session 6
Jsp   session 6Jsp   session 6
Jsp session 6
Anuj Singh Rajput
 
JSP Part 2
JSP Part 2JSP Part 2
JSP Part 2
DeeptiJava
 
J2EE jsp_03
J2EE jsp_03J2EE jsp_03
J2EE jsp_03
Biswabrata Banerjee
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
Rami Nayan
 
Web&java. jsp
Web&java. jspWeb&java. jsp
Web&java. jsp
Asya Dudnik
 
Web&java. jsp
Web&java. jspWeb&java. jsp
Web&java. jsp
Asya Dudnik
 
Learning jsp
Learning jspLearning jsp
Learning jsp
mustafacse2009
 

Similar to Advance java session 12 (20)

Using java beans(ii)
Using java beans(ii)Using java beans(ii)
Using java beans(ii)
 
Jsp
JspJsp
Jsp
 
Java Beans
Java BeansJava Beans
Java Beans
 
Java Beans Unit 4(Part 1)
Java Beans Unit 4(Part 1)Java Beans Unit 4(Part 1)
Java Beans Unit 4(Part 1)
 
KMUTNB - Internet Programming 5/7
KMUTNB - Internet Programming 5/7KMUTNB - Internet Programming 5/7
KMUTNB - Internet Programming 5/7
 
KMUTNB - Internet Programming 5/7
KMUTNB - Internet Programming 5/7KMUTNB - Internet Programming 5/7
KMUTNB - Internet Programming 5/7
 
ADP - Chapter 5 Exploring JavaServer Pages Technology
ADP - Chapter 5 Exploring JavaServer Pages TechnologyADP - Chapter 5 Exploring JavaServer Pages Technology
ADP - Chapter 5 Exploring JavaServer Pages Technology
 
Intro To Sap Netweaver Java
Intro To Sap Netweaver JavaIntro To Sap Netweaver Java
Intro To Sap Netweaver Java
 
Jpa queries
Jpa queriesJpa queries
Jpa queries
 
Jsp session 5
Jsp   session 5Jsp   session 5
Jsp session 5
 
java beans
java beansjava beans
java beans
 
Session 44 - Spring - Part 2 - Autowiring, Annotations, Java based Configuration
Session 44 - Spring - Part 2 - Autowiring, Annotations, Java based ConfigurationSession 44 - Spring - Part 2 - Autowiring, Annotations, Java based Configuration
Session 44 - Spring - Part 2 - Autowiring, Annotations, Java based Configuration
 
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slidesSpring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
 
Jsp session 6
Jsp   session 6Jsp   session 6
Jsp session 6
 
JSP Part 2
JSP Part 2JSP Part 2
JSP Part 2
 
J2EE jsp_03
J2EE jsp_03J2EE jsp_03
J2EE jsp_03
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Web&java. jsp
Web&java. jspWeb&java. jsp
Web&java. jsp
 
Web&java. jsp
Web&java. jspWeb&java. jsp
Web&java. jsp
 
Learning jsp
Learning jspLearning jsp
Learning jsp
 

More from Smita B Kumar

Advance java session 20
Advance java session 20Advance java session 20
Advance java session 20
Smita B Kumar
 
Advance java session 19
Advance java session 19Advance java session 19
Advance java session 19
Smita B Kumar
 
Advance java session 18
Advance java session 18Advance java session 18
Advance java session 18
Smita B Kumar
 
Advance java session 17
Advance java session 17Advance java session 17
Advance java session 17
Smita B Kumar
 
Advance java session 16
Advance java session 16Advance java session 16
Advance java session 16
Smita B Kumar
 
Advance java session 15
Advance java session 15Advance java session 15
Advance java session 15
Smita B Kumar
 
Advance java session 14
Advance java session 14Advance java session 14
Advance java session 14
Smita B Kumar
 
Advance java session 13
Advance java session 13Advance java session 13
Advance java session 13
Smita B Kumar
 
Advance java session 11
Advance java session 11Advance java session 11
Advance java session 11
Smita B Kumar
 
Advance java session 10
Advance java session 10Advance java session 10
Advance java session 10
Smita B Kumar
 
Advance java session 9
Advance java session 9Advance java session 9
Advance java session 9
Smita B Kumar
 
Advance java session 8
Advance java session 8Advance java session 8
Advance java session 8
Smita B Kumar
 
Advance java session 7
Advance java session 7Advance java session 7
Advance java session 7
Smita B Kumar
 
Advance java session 6
Advance java session 6Advance java session 6
Advance java session 6
Smita B Kumar
 
Advance java session 5
Advance java session 5Advance java session 5
Advance java session 5
Smita B Kumar
 
Advance java session 4
Advance java session 4Advance java session 4
Advance java session 4
Smita B Kumar
 
Advance java session 3
Advance java session 3Advance java session 3
Advance java session 3
Smita B Kumar
 
Advance java session 2
Advance java session 2Advance java session 2
Advance java session 2
Smita B Kumar
 
JEE session 1
JEE session 1JEE session 1
JEE session 1
Smita B Kumar
 
01 introduction to struts2
01 introduction to struts201 introduction to struts2
01 introduction to struts2
Smita B Kumar
 

More from Smita B Kumar (20)

Advance java session 20
Advance java session 20Advance java session 20
Advance java session 20
 
Advance java session 19
Advance java session 19Advance java session 19
Advance java session 19
 
Advance java session 18
Advance java session 18Advance java session 18
Advance java session 18
 
Advance java session 17
Advance java session 17Advance java session 17
Advance java session 17
 
Advance java session 16
Advance java session 16Advance java session 16
Advance java session 16
 
Advance java session 15
Advance java session 15Advance java session 15
Advance java session 15
 
Advance java session 14
Advance java session 14Advance java session 14
Advance java session 14
 
Advance java session 13
Advance java session 13Advance java session 13
Advance java session 13
 
Advance java session 11
Advance java session 11Advance java session 11
Advance java session 11
 
Advance java session 10
Advance java session 10Advance java session 10
Advance java session 10
 
Advance java session 9
Advance java session 9Advance java session 9
Advance java session 9
 
Advance java session 8
Advance java session 8Advance java session 8
Advance java session 8
 
Advance java session 7
Advance java session 7Advance java session 7
Advance java session 7
 
Advance java session 6
Advance java session 6Advance java session 6
Advance java session 6
 
Advance java session 5
Advance java session 5Advance java session 5
Advance java session 5
 
Advance java session 4
Advance java session 4Advance java session 4
Advance java session 4
 
Advance java session 3
Advance java session 3Advance java session 3
Advance java session 3
 
Advance java session 2
Advance java session 2Advance java session 2
Advance java session 2
 
JEE session 1
JEE session 1JEE session 1
JEE session 1
 
01 introduction to struts2
01 introduction to struts201 introduction to struts2
01 introduction to struts2
 

Recently uploaded

UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
Pixlogix Infotech
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Zilliz
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Zilliz
 

Recently uploaded (20)

UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
 

Advance java session 12

  • 2. Agenda • Understanding the benefits of beans • Creating beans • Installing beans classes on server • Accessing bean properties
  • 3. What is JavaBean • JavaBean is reusable software components • Rules for creating Java Bean - Public class - Private/protected instance variable - Zero-arg constructor - Public getter and setter methods(accessor and mutator ) • Any java class which satisfies the above rule is a Java Bean
  • 4. Why use a JavaBeans Component • A JSP page can create and use any type of Java programming language object within a declaration or scriptlet. The following scriptlet creates the bookstore shopping cart and stores it as a session attribute: - <% ShoppingCart cart = (ShoppingCart)session. getAttribute("cart"); // If the user has no cart, create a new one if (cart == null) { cart = new ShoppingCart(); session.setAttribute("cart", cart); } %> • If the shopping cart object conforms to JavaBeans conventions, JSP pages can use JSP elements to create and access the object. For example, the Duke's Bookstore pages bookdetails.jsp, catalog.jsp, and showcart.jsp replace the scriptlet with the much more concise JSP useBean element: <jsp:useBean id="beanName" class="fully_qualified_classname" scope="scope"/> Or <jsp:useBean id="beanName" class="fully_qualified_classname“ scope="scope"> <jsp:setProperty /> </jsp:useBean>
  • 5. Types of properties • Simple Properties - private String name • Indexed properties - private String[] skills • Boolean properties - private boolean experienced
  • 6. How to access javabean in JSP • <jsp:useBean> action - Enables JSP to manipulate Java object • Creates Java object or locates an existing object for use in JSP • Location can be - Page Scope - Request Scope - Session Scope - Application Scope
  • 7. <jsp:useBean> attributes Attribute Description id The name used to manipulate the Java object with actions <jsp:setProperty> and <jsp:getProperty>. A variable of this name is also declared for use in JSP scripting elements. The name specified here is case sensitive. scope The scope in which the Java object is accessible—page, request, session or application. The default scope is page. class The fully qualified class name of the Java object. beanName The name of a bean that can be used with method instantiate of class java.beans.Beans to load a JavaBean into memory. type The type of the JavaBean. This can be the same type as the class attribute, a superclass of that type or an interface implemented by that type. The default value is the same as for attribute class. A ClassCastException occurs if the Java object is not of the type specified with attribute type.
  • 8. <jsp:useBean> attributes( cont) Attribute Description name The ID of the JavaBean for which a property (or properties) will be set. property The name of the property to set. Specifying "*"for this attribute causes the JSP to match the request parameters to the properties of the bean.For each request parameter that matches (i.e., the name of the request parameter is identical to the bean’s property name), the corresponding property in the bean is set to the value of the parameter. If the value of the request parameter is"", the property value in the bean remains unchanged. param If request parameter names do not match bean property names, this attribute can be used to specify which request parameter should be used to obtain the value for a specific bean property. This attribute is optional. If this attribute is omitted, the request parameter names must match bean property names. value The value to assign to a bean property. The value typically is the result of a JSP expression. This attribute is particularly useful for setting bean properties that cannot be set using request parameters. This attribute is optional. If this attribute is omitted, the JavaBean property must be of a type that can be set using request parameters. Fig. 25.16 Attributes of the <jsp:setProperty> action.
  • 9. JavaBean Example package mypack; public class Student { private String name; private int rollno; public Student(){} public Student(String name, int rollno) { this.name = name; this.rollno = rollno; } public String getName() { return name; } public void setName(String name) {this.name = name; } public int getRollno() { return rollno; } public void setRollno(int rollno) { this.rollno = rollno; } }
  • 10. Setting the properties <jsp:useBean id=“student" class=“mypack.Student" scope="session"> <jsp:setProperty name=“student" property=“name“ value=“king” /> <jsp:setProperty name=“student” property=“rollno” value=“21” /> </jsp:useBean> 1. beanName must be the same as that specified for the id attribute in a useBean element. 2. There must be a setPropName method in the JavaBeans component. 3. paramName must be a request parameter name.
  • 11. Setting the properties Value Source Element Syntax String constant <jsp:setProperty name="beanName" property="propName" value="string constant"/> Request parameter <jsp:setProperty name="beanName" property="propName" param="paramName"/> Request parameter name matches bean property <jsp:setProperty name="beanName" property="propName"/> <jsp:setProperty name="beanName" property="*"/> Expression <jsp:setProperty name="beanName" property="propName" value="<%= expression %>"/>
  • 12. Accessing javaBean in jsp <html> <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <body> <jsp:useBean id="s" class="mypack.Student" scope="session"> <jsp:setProperty name="s" property="name" value="ma ma"/> <jsp:setProperty name="s" property="rollno" value="1"/> </jsp:useBean> <jsp:getProperty name="s" property=“name”/> <jsp:getProperty name="s" property="rollno"/> </body> </html>
  • 13. Advantages of JavaBean • “Write once run anywhere” • Reusable Components • Seperation of Business logic from Presentation and Navigation • Loosely Coupled • EJB can also be used for business logic • No need to implement any API for creating a JavaBean • Using reflection can access properties, method easily dynamically
  • 14. Summary • JavaBean is a specification • Simple convention for creating JavaBean • Best Practises • Standard action to create and access the JavaBean • Standard action to read their content • EL can also be used to access the properties