Objectives: •Understand what are Java Beans and how it is applied to JSP •Learn to process information using Java Beans •Understand the JSP tags pertaining to Java Beans Concepts •Java Beans are reusable software c omponents oWe can write a Java Bean that can be used in a variety of other Java applications •A Java Bean is just a Java class. It must adhere with the following rules oIt has a public class oIt has a public constructor with no arguments oIt has a public get and set method to read and write to properties You just need to define a class that has a field corresponding to each field in the form The class fields must have “setters ” and getters that match the names of the form fields The “setter” method is j ust a method that starts with “set” followed by the name of the field. The first character of the field name is upper-cased Getter methods are defined similarly with “get’ instead of “set” •The benefit of Java Beans is that HTML programmers and graphic designers can do presentation development while the Java programmer can do t he programming logic. •By using Java Beans you can fully separate the business logic from the generation of display JSP Java Beans Tags •<jsp:useBean> •<jsp:setProperty> •<jsp:getProperty> <jsp:useBean> oThis tag is used to declare and instantiate t he Java Bean class. oSyntax: <jsp:useBean id=”object-name” scope=”page | request | session | application” type=”type-of-object”
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.