JAVABEAN's Application Java Server Pages (JSP) component technology is known as the Java component of Bean. The structure of Bean must meet a certain naming convention. JavaBean is similar to the ActiveX control: they all provide common functions and can be reused. These agreements are developed by Sun and several other companies, called JavaBeans API. Just comply with Java Beansapi naming conventions, you can develop reusable, separate Java components. In JSP, use the bean tag collection, the content developer does not need to write any code to add dynamic elements to the page with Java power. In the development of JSP, the large segment of the code is often placed in the script clip (Scriptle), but most of the Java code belongs to reuse (such as database connection to the connection), so you can make this duplicate code Javabea components. The value of JavaBean is obtained through some properties, and you can access JavaBean settings through these properties. Now how to adjust JavaBean in JSP is as follows: To use "bean" in JSP, you must first set the bean to reference to the JSP to generate an instance of the bean. Can use"
"Mark to complete:
. "
"The tag is identified by the" ID "attribute. When the" ID "property is specified, you must tell you where to find bean, or what is the Java category. The last required element is" scope "Properties. With the help of" scope "attribute, you can tell bean as a single page (default) [scope =" page "], for a requesting web page [scope =" request "], request as a session [ Scope = "session"], or for the entire application [Scope = "Application"] keeps the information. With the scope of the session, you can easily maintain items on the website on the JSP website, such as shopping cart items, etc. Instantiate a JavaBean, you can access its properties to customize it. To get attribute values, please use "
"Mark. Use this tag to specify the bean name (from the UseBean" ID "field) and the properties you want to get the value. The actual value is placed in the output:
. To change the JavaBean property, you must use "
"Tag. For this mark, you need to recognize the bean and its properties again to modify and provide additional new values. If naming is correct, these values can be obtained directly from a submitted table: Parameter Get:
Can be obtained from a parameter, but must be naming the properties and parameters directly:
Or use a name and value directly:
/?>. About JavaBean: For the web server, you can find Javabean, you need to place its category file in a special location of the web server. In RESIN is placed in the "Doc / Web-INF / CLASSES" directory. Example: This simple example is to complete the settings and acquisition of the product and tax rate. package tax; public class TaxRate {String Product; 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 set (Double RateValue) {this.rate = rate ()} PUBLIC DOUBLE GETRATE () {Return (this.rate);}} Sample_Bean.jsp Modified
Product:
Tax rate:
After modification:
Product:
Tax rate:
Put Taxrate.java in the "Doc / Web-INF / CLASS / DOC" directory of Resin, Sample_Bean.jsp puts it in the doc directory of Resin. Run under the browser: http: // localhost: 8080 / sample_bean.jsp can see the effect. From the above explanations and applications, it can be seen that due to the use of component technology and the introduction of the JavaBeans API, JSP allows Java developers to quickly decompose a site into some of the small, reusable components. These components are used as HTML elements for each of the needs of JSP. This implementation allows development efforts to be divided into two parts: performance and content.