Use JavaBean components

xiaoxiao2021-03-06  55

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 tag in the JSP page. Depending on the different JSP engine, where it is configured and how to configure bean may also be slightly different. This article places this bean's .class file in the C: JSWDK-1.0ExamplesWeb-Infjspeans AX directory, the TAX here is a directory that stores the bean.

Below is an example page applying the above bean: <% @ page language = "java"%> <% TaxBean.SetProduct ("A002"); TAXBean.Setrate (17);%> Usage 1:

Products: <% = TaxBean.getProduct ()%>
Tax rate: <% = TaxBean.Getrate ()%>

<% TAXBean.SetProduct ("A003"); TaxBean.Setrate (3);%> How to use 2:

Products:
tax rate: Declined in tag Attribute, where ID is an identifier of the BEAN within the entire JSP page, the scope attribute defines the living time of the bean, and the class attribute illustrates the bean class file (starting from the package name). 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 tag is used. The name attribute in is the ID of the bean, which specifies the name of the target property. 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. Explanation:

转载请注明原文地址:https://www.9cbs.com/read-116594.html

New Post(0)