Creating the Java Bean

You now create a Java bean, which is associated with the view that you have just created.

  1. In Project Explorer, right-click Java Resources in the JSPBookDemo project, and select New > Class.
  2. Type in the Package field, and BookBean in the Name field.
  3. Click Finish to create the BookBean class file.
  4. Overwrite the skeleton contents of the file with the contents from the file that you downloaded previously (the file is stored in C:\myfiles\COBOL_JSP_DEMO_2_2_SRC\JSPBookDemo\src\com\microfocus\book).
  5. Click File > Save.


A bean is used to separate the business logic from the presentation logic, and a bean is simply an instance of a class. This class contains the information that will be displayed in the JSP view.

In this tutorial, at run time, the dispatching servlet binds an appropriate bean to the attribute "book" before calling the JSP. For example, in the book.stockno variable that was created previously in the JSP file, the JSP invokes the getStockno method on BookBean, and inserts the return value into the JSP output.