Author: tianma
Although you can place a large segment of code in a script segment (scriptlet), the vast majority of Java code is a reusable component named JavaBea. JavaBean is similar to ActiveX Controls: they provide common functions and can be reused.
The value of JavaBean is obtained through some attributes. You can access the JavaBean settings through these attributes. For example, a person is a JavaBean, whose name, ID number, and address are attributes. On the JSP website, you basically make your website dynamic by playing "Connect the beans.
Suppose that the JavaBean is created before the website. The first thing you need to do is to tell the JSP page that it will use a "Bean ". You can use the <jsp: useBean> mark to do this:
<Jsp: useBean id = "localName" class = "com. jguru. Person" scope = "application"/>.
The "<jsp: useBean>" tag requires that you use the "id" attribute to identify the Bean. Here you provide a Bean named for the rest of the JSP page. In addition to the "id" attribute, you must also tell the webpage where to find the Bean or its Java class name. This type attribute provides the Bean validation function. Other methods can also do this. The last required element is the "scope" attribute. With the help of the "scope" attribute, you can tell the Bean to be a single page (default) [scope = "page"], [scope = "request"] the request is a session [scope = "session"], or leave information for the entire application [scope = "application. With the session range, you can easily maintain items such as shopping carts on the JSP page.
Once you become a JavaBean, you can access its attributes to customize it. To obtain the property value, mark it with <jsp: getProperty>. With this tag, you can specify the name of the Bean to be used (obtained from the "id" Field of useBean) and the attribute of the Bean value you want. The actual value is put in the output:
<Jsp: getProperty id = "localName" property = "name"/>.
To change the JavaBean attribute, you must use the <jsp: setProperty> tag. For this tag, you need to identify the Bean and attributes again to modify and provide additional values. If the name is correct, these values can be obtained directly from a submitted table: parameter:
<Jsp: setProperty id = "localName" property = "*"/>;
It can be obtained from a parameter, but you must directly name the attributes and parameters:
<Jsp: setProperty id = "localName" property = "serialNumber" value = "string"/>
You can also directly set the value using a name and value: <jsp: setProperty id = "localName" property = "serialNumber" value = <% = expression %>/>.
The last thing about JavaBean: In order for the Web server to find JavaBean, You need to place its category files in a special location. With JSWDK, the most convenient location is the class directory under the installation directory, such as the jswdk-1.0.1classes.