13.3. Setting Bean Properties
You normally use jsp:setProperty to set bean properties. The simplest form of this action takes three attributes: name (which should match the id given by jsp:useBean), property (the name of the property to change), and value (the new value).
For example, the SaleEntry class shown in Listing 13.3 has an itemID property (a String), a numItems property (an int), a discountCode property (a double), and two read-only properties itemCost and totalCost (each of type double). Listing 13.4 shows a JSP file that builds an instance of the SaleEntry class by means of:
<jsp:useBean id="entry" class="coreservlets.SaleEntry" />
The results are shown in Figure 13-2.
Figure 13-2. Result of SaleEntry1.jsp.
Once the bean is instantiated, ...
Get Core Servlets and JavaServer Pages™ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.