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. Here is the code list of this bean:
Package Tax;
Public class Taxrate {
String products;
Double Rate;
Public Taxrate () {
this.Product = "A001";
THIS.RATE = 5;
}
Public void setProduct (String ProductName) {
THIS.PRODUCT = ProductName;
}
Public string getProduct () {
Return (this.Product);
}
Public void setrate (double rateue) {
THIS.RATE = RateValue;
}
Public double getrate () {
Return (this.rate);
}
}
Apply the above Bean to the
<% @ Page language = "java"%>
<% TaxBean.SetProduct ("A002");
TaxBean.Setrate (17);
%>
How to use 1:
Product: <% = TaxBean.getProduct ()%>
Tax rate: <% = TaxBean.Getrate ()%>
<% TaxBean.SetProduct ("A003");
TaxBean.Setrate (3);
%>
How to use 2: b>
Product:
Tax rate:
Body>
Html>
Several properties are defined within the
This JSP page not only uses the BEAN's SET and GET method settings and extraction attribute values, but also uses the second method of extracting the bean property value, even if the
It turns out that Java Servlet is an ideal architecture for developing web applications. JSP is based on servlet technology and has been improved in many respects. The JSP page looks like a normal HTML page, but it allows embedding code, at this point, it is very similar to the ASP technology. With a cross-platform JavaBean component, JSP provides excellent solutions for separation processing logic and display style. JSP will become a strong competitor of ASP technology