Although you can put a large chunk of program code in a small instruction file, most Java program code belongs to reusable components called JavaBean. JavaBean are like ActiveX controls: They provide known functionality and are designed to be reusable for any purpose.
The value of JavaBean is that it can be used through a set of features that provide access to JavaBean settings. As an example, the person is JavaBean, and his name, social security number, and address can be characteristic. For JSP sites, basically you are ' JavaBean ' dynamically connected to your site.
Assuming that JavaBean is built before the site is built, the first thing you need to do is to tell the JSP page that it needs to use JavaBean. This work can be done with the <jsp:useBean> label: <jsp:usebean id= " LocalName "class=" Com.jguru.Person "scope=" Application "/>";
<jsp:useBean> labels require you to identify the beans with the id attribute. Here, you provide a name for the JSP page to identify the beans, in addition to the ID attribute, you must also tell the page where to find the beans, or its Java class name. The category attribute provides a way to find it in a variety of ways, and the last component that is required is the scope property. With the help of the range attribute, you can tell the beans that you want it for a single page (preset) [scope= "page"]; for a requested web page [scope= "Request"] For the duration of the call [scope= "session"], or for the entire application [scope= "Application"] to maintain its own information. For the duration of the call, you can easily maintain the items in the JSP page, such as the shopping cart.
Once you have declared the JavaBean, you can access its features to fix it. To obtain the value of an attribute, use the <jsp:getProperty> volume label. With the <jsp:getProperty> label, you can specify the name of the bean to use (from the Usebean ID field), and the attributes of the value you want to get. The real value is then placed in the output: <jsp:getproperty id= "LocalName" property= "name"/>.
To change the characteristics of the JavaBean, you need to use the <jsp:setProperty> volume label. You also need to identify the beans and the features to be corrected for this label, but you also need to provide new values. If the name is correct, these can be obtained directly through the prescribed format:< Jsp:setproperty id= "LocalName" property= "*"/>;
To get from one parameter, you must directly name this attribute as well as the parameters: <jsp:setproperty id= "LocalName" property= "Address" param= "parametername"/>;
or set directly by name and value: <jsp:setproperty id= "LocalName" property= "SerialNumber" value= "string"/> or <jsp:setproperty Id= "LocalName" property= "serialnumber" value= <%= expression%>/>.
The last point about JavaBean: to get the Web server to find JavaBean, you need to put their category files in a special location. The simplest place for JSWDK is the category directory in the installation directory, such as jswdk-1.0.1classes.