Java Beans in Servlets and JSP

This chapter wouldn't be complete without pointing out the role of Java beans on the server side. Java beans are software components, namely well-specified “modules” that do a specific job and can easily be reused in many applications. Microsoft makes extensive use of software components under the product name ActiveX, often for some visual or GUI feature.

For example, a programmer might write a piece of code that can display a set of numbers as a pie chart. That routine is very suitable for turning into a software component, making it available to any program on the system.

The point of JSP is to use lots of Java beans that cover your business processes. You might have one bean that encompasses everything you can do with a customer record, another for an order, and a third that represents a payment transaction. JSP lets you easily integrate these beans in a web-based display framework. JSP has a special tag that lets web pages on the server easily interact with beans with hardly any “glue” code needed. People call this a “tag library.”

Here's an example of the tags that connect a JSP page to a Java bean that manages database access.

<%@ page language="java" import="java.sql.*" %>

<jsp:useBean id="db" scope="request"
  class="com.afu.database.DbBean" />

<jsp:setProperty name="db" property="*" />

You use the same beans (the same logic) for your non-web-based processing so you have the advantages of consistency, familiarity, and software reuse. The combination of Java beans and JSP is a major use of JSP.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.182.159