Using JavaBeans in JavaServer Pages - Chương 3
Số trang: 31
Loại file: ppt
Dung lượng: 83.50 KB
Lượt xem: 17
Lượt tải: 0
Xem trước 4 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Session Objectives Describe the various features of a JavaBean Differentiate between a JavaBean and a Java class Describe the basic structure of a JavaBean Describe the various ways of creating beans Describe the advantages of using beans Explain how to access beans through JSP scriptlets Describe the use of various JSP bean tags Define the scope of beans
Nội dung trích xuất từ tài liệu:
Using JavaBeans in JavaServer Pages - Chương 3 UsingJavaBeansin JavaServerPages Chương3 SessionObjectives DescribethevariousfeaturesofaJavaBean DifferentiatebetweenaJavaBeanandaJavaclass DescribethebasicstructureofaJavaBean Describethevariouswaysofcreatingbeans Describetheadvantagesofusingbeans ExplainhowtoaccessbeansthroughJSPscriptlets DescribetheuseofvariousJSPbeantags Definethescopeofbeans /2of36 WhatisaJavaBean? JavaBeansbringscomponenttechnology totheJavaplatform WiththehelpoftheJavaBeansAPI,youcancreate reusableandplatformindependentcomponents Thesecomponentscanbecombinedintoapplets, applications,orcompositecomponentsJavaBeanoraBean,isasimpleJavaclassthatfollows asetofnaminganddesignconventions, outlinedbytheJavaBeansspecifications /3of36 Differencebetweena JavaBeanandaJavaclassAbeanisaJavaclasswiththefollowingadditionalcharacteristics: Theclassmustbeinstantiable Itmusthaveadefaultconstructor Itmustbeserializable ItmustfollowtheJavaBeansdesignpatterns /4of36 JavaBeansDesignPatterns Namingconventionsforbeanmethodsand datamembers Designpatternsareimportantfor introspection Introspection:mechanismusingcomponents makesitsinternalstructureknowntotheoutside world? Methodsareexposedthroughreflection /5of36 AnExampleofaJavaBean Propertypublic class Tower { private float height; public float getHeight() { getPropertyName() return height; } public void setHeight(float h) { height = h; } setPropertyName() public boolean isGreaterHeight(int initialHeight, int finalHeight) { if((finalHeight - initialHeight) > 0) { return true; } else { return false;} } public Tower() { height = (float)10.5; } } /6of36 UsingJSPBeanTags JSPprovidesthreebasicbeantags: Tofindandusethebean–jsp:useBean Tosetoneormoreproperties–jsp:setProperty Togetaproperty–jsp:getProperty Thesearealsoknownasactionsandare specifictagsthataffectthefollowing: theruntimebehavioroftheJSP theresponsesthataresentbacktotheclient /7of36UsingJSPBeanTags–(1) getProperty_Name() setProperty_Name(value) TheJSPneednotknowthe innerstructureofthebean Bean TheBlackboxapproach /8of36 jsp:useBean ThisisusedtoassociateaJavaBeaninJSP. Itensuresthattheobjectcanbereferenced fromJSP,usinganIDandscope Thebeanclass mustbeavailable Thesyntaxisasfollows: totheJSPengine jsp:useBean–(1) beanDetailsisoneof: class = className class = className type = typeName beanName = beanName type = typeName type = typeName /10of36 ScopeofBeans page Thebeanwilldisappearassoonasthecurrentpage finishesgenerating Referencestothisobjectwillonlybereleasedafterthe responseissentbacktotheclient request Thebeaninstancewillbeavailableaslongasthe requestobjectisavailable Referencestothisobjectwillbereleasedonlyafterthe requestisprocessedcompletely /11of36 ScopeofBeans–(1) session Theinstancewillbeavailableacrossaparticularsession betweenthebrowserofaparticularmachineandthe Webserver Referencestothisobjectwillbereleasedonlyafterthe associatedsessionsend application Theinstancewillbeavailabletoallusersandpagesof theapplication Itisreleasedonlywhentheruntimeenvironment reclaimstheServletContext /12of36 AnExample Thescopeisset. tothesession.This is used to instantiate the bean Hello World! /13of36 SessionScope Beans with session scope are accessible only within pages processing requests that are in the same session as the one in which the bean was created Beans cannot be defined in a page whose page directivehasanattributesession=false References to the session scope are stored in the sessionobject Thebeanisdistinctforeveryclientandisvaluable aslongastheclient’ssessionisvalid /14of36 SessionScope–(1) AnExampleThefirstJSP . . . Instantiatethe Counterbean A Session bean: The First Example The cur ...
Nội dung trích xuất từ tài liệu:
Using JavaBeans in JavaServer Pages - Chương 3 UsingJavaBeansin JavaServerPages Chương3 SessionObjectives DescribethevariousfeaturesofaJavaBean DifferentiatebetweenaJavaBeanandaJavaclass DescribethebasicstructureofaJavaBean Describethevariouswaysofcreatingbeans Describetheadvantagesofusingbeans ExplainhowtoaccessbeansthroughJSPscriptlets DescribetheuseofvariousJSPbeantags Definethescopeofbeans /2of36 WhatisaJavaBean? JavaBeansbringscomponenttechnology totheJavaplatform WiththehelpoftheJavaBeansAPI,youcancreate reusableandplatformindependentcomponents Thesecomponentscanbecombinedintoapplets, applications,orcompositecomponentsJavaBeanoraBean,isasimpleJavaclassthatfollows asetofnaminganddesignconventions, outlinedbytheJavaBeansspecifications /3of36 Differencebetweena JavaBeanandaJavaclassAbeanisaJavaclasswiththefollowingadditionalcharacteristics: Theclassmustbeinstantiable Itmusthaveadefaultconstructor Itmustbeserializable ItmustfollowtheJavaBeansdesignpatterns /4of36 JavaBeansDesignPatterns Namingconventionsforbeanmethodsand datamembers Designpatternsareimportantfor introspection Introspection:mechanismusingcomponents makesitsinternalstructureknowntotheoutside world? Methodsareexposedthroughreflection /5of36 AnExampleofaJavaBean Propertypublic class Tower { private float height; public float getHeight() { getPropertyName() return height; } public void setHeight(float h) { height = h; } setPropertyName() public boolean isGreaterHeight(int initialHeight, int finalHeight) { if((finalHeight - initialHeight) > 0) { return true; } else { return false;} } public Tower() { height = (float)10.5; } } /6of36 UsingJSPBeanTags JSPprovidesthreebasicbeantags: Tofindandusethebean–jsp:useBean Tosetoneormoreproperties–jsp:setProperty Togetaproperty–jsp:getProperty Thesearealsoknownasactionsandare specifictagsthataffectthefollowing: theruntimebehavioroftheJSP theresponsesthataresentbacktotheclient /7of36UsingJSPBeanTags–(1) getProperty_Name() setProperty_Name(value) TheJSPneednotknowthe innerstructureofthebean Bean TheBlackboxapproach /8of36 jsp:useBean ThisisusedtoassociateaJavaBeaninJSP. Itensuresthattheobjectcanbereferenced fromJSP,usinganIDandscope Thebeanclass mustbeavailable Thesyntaxisasfollows: totheJSPengine jsp:useBean–(1) beanDetailsisoneof: class = className class = className type = typeName beanName = beanName type = typeName type = typeName /10of36 ScopeofBeans page Thebeanwilldisappearassoonasthecurrentpage finishesgenerating Referencestothisobjectwillonlybereleasedafterthe responseissentbacktotheclient request Thebeaninstancewillbeavailableaslongasthe requestobjectisavailable Referencestothisobjectwillbereleasedonlyafterthe requestisprocessedcompletely /11of36 ScopeofBeans–(1) session Theinstancewillbeavailableacrossaparticularsession betweenthebrowserofaparticularmachineandthe Webserver Referencestothisobjectwillbereleasedonlyafterthe associatedsessionsend application Theinstancewillbeavailabletoallusersandpagesof theapplication Itisreleasedonlywhentheruntimeenvironment reclaimstheServletContext /12of36 AnExample Thescopeisset. tothesession.This is used to instantiate the bean Hello World! /13of36 SessionScope Beans with session scope are accessible only within pages processing requests that are in the same session as the one in which the bean was created Beans cannot be defined in a page whose page directivehasanattributesession=false References to the session scope are stored in the sessionobject Thebeanisdistinctforeveryclientandisvaluable aslongastheclient’ssessionisvalid /14of36 SessionScope–(1) AnExampleThefirstJSP . . . Instantiatethe Counterbean A Session bean: The First Example The cur ...
Tìm kiếm theo từ khóa liên quan:
công nghệ thông tin kỹ thuật lập trình tin học vi tính Using JavaBeans JavaServer PagesTài liệu có liên quan:
-
52 trang 468 1 0
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 367 0 0 -
96 trang 334 0 0
-
74 trang 329 0 0
-
Đồ án tốt nghiệp: Xây dựng ứng dụng di động android quản lý khách hàng cắt tóc
81 trang 321 0 0 -
Tài liệu dạy học môn Tin học trong chương trình đào tạo trình độ cao đẳng
348 trang 321 1 0 -
Kỹ thuật lập trình trên Visual Basic 2005
148 trang 310 0 0 -
Báo cáo thực tập thực tế: Nghiên cứu và xây dựng website bằng Wordpress
24 trang 304 0 0 -
Tài liệu hướng dẫn sử dụng thư điện tử tài nguyên và môi trường
72 trang 303 0 0 -
EBay - Internet và câu chuyện thần kỳ: Phần 1
143 trang 297 0 0