CNET JSP basic:jsp and JavaBean

Source: Internet
Author: User
Although you can put a large chunk of code in a small instruction file, most Java code is a reusable component called JavaBean. JavaBean are like ActiveX controls: They provide known functionality and are designed to be reusable for any purpose.

JavaBean's ¤ value 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 JavaBean is built before the site is built, the first thing you need to do is tell the JSP page what it wants to use JavaBean. This work can be done with <jsp:useBean> tags:
<jsp:usebean id= "LocalName" class= "Com.jguru.Person" scope= "Application"/>.

The <jsp:useBean> label requires 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 property provides a way to find it in a variety of ways, and the last component to be the scope property. With the help of the range attribute, you can tell the beans to have it for a single page (preset) [scope= "page"]; for a requested webpage [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 proclaimed the JavaBean, you will be able to access its features to set it. To get the value of an attribute, use the <jsp:getProperty> label. With <jsp:getProperty> tags, 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. Then the real value is placed in the output:
<jsp:getproperty id= "LocalName" property= "name"/>.

To change the characteristics of the JavaBean, you need to use the <jsp:setProperty> tag. For this label, you also need to identify the beans and the features you want to modify, and you will 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 the attribute as well as the parameters:
<jsp:setproperty id= "LocalName" property= "Address" param= "parametername"/>;

Or you can set it 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 allow Web servers to find JavaBean, you have 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.1\classes.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.