JavaBean is a Java-based software component. JSP provides perfect support for integrating Javabean components in web applications. This support not only reduces development time (can directly utilize test and trusted components, avoid repeated development), but also bring more scalability for JSP applications. JavaBean components can be used to perform complex computing tasks or are responsible for interaction with the database and data extraction. If we have three Javabeans, they have functions of displaying news, stock prices, and weather conditions, and create a web page containing all three functions. It only needs to instantiate these three beans. You can use the HTML form to position them. . To illustrate the application of JavaBean in a JSP environment, we created a bean called TaxRate. It has two properties, namely Product (product) and RATE (tax rate). Two set methods are used to set these two properties, and the two GET methods are used to extract these two properties. In practical applications, this bean should generally extract tax rates from the database, which we simplifies this process, allowing any set tax rate. Below is this bean code list: package tax; public class taxrate {string product; double rate; public Taxrate () {this.Roduct = "A001"; this.rate = 5;} public void setProduct (String product "{THIS .Product = ProductName;} public String getProduct () {return (this.Product);} public void setRate (double rateValue) {this.Rate = rateValue;} public double getRate () {return (this.Rate);}} Apply the above Bean to the
Below is an example page applying the above bean:
<% @ page language = "java"%> Products: <% = TaxBean.getProduct ()%>
Tax rate: <% = TaxBean.Getrate ()%>
<% TAXBean.SetProduct ("A003"); TaxBean.Setrate (3);%> How to use 2: b>
Products:
tax rate: