Analysis of JavaBean usage in JSP learning and jspjavabean usage

Source: Internet
Author: User

Analysis of JavaBean usage in JSP learning and jspjavabean usage

This document describes how to use Java Beans for JSP learning. Share it with you for your reference. The details are as follows:

JavaBean is a Java class that complies with certain naming methods and design specifications.
JavaBean can be used to execute complex computing tasks, encapsulate transaction logic, databases, and other operations.
JavaBean can be divided into visual JavaBean, such as buttons, text boxes, list boxes, and other non-visual JavaBean, such as operations and database connections.

Use JavaBean:

Copy codeThe Code is as follows: <jsp: useBean id = "name" scope = "page | request | session | application" typeSpec = "typename"/>

Four values of typeSpec:

Class = "classname" class indicates the class path and class Name
Class = "classname" type = "typename" type indicates the type of the class, which can be the class, parent class, or interface.
BeanName = "beanName" type = "typename", beanName indicates the name of the JavaBean, Which is initialized using the java. beans. Beans. instantiate () method in the form of a. B. c
Type = "typename"

<Jsp: setProperty> used to set the attribute value of JavaBean:

<jsp:setProperty name="beanname" property="*"><jsp:setProperty name="beanname" property="propertyname"><jsp:setProperty name="beanname" property="propertyname" param="paramname"><jsp:setProperty name="beanname" property="propertyname" value="beanvalue">

Beanname indicates the name of the JavaBean instance.
Propertyname indicates the property name of JavaBean.
Paramname specifies the parameter name in the request object
Beanvalue is used to set the attribute value of JavaBean.
<Jsp: getProperty>:
<Jsp: getProperty name = "beanname" property = "propertyname">
It is equivalent to the getXX function in JavaBean.
<Jsp: setProperty name = "splBean" property = "id" value = "$ {param. id}"/>

About the Declaration cycle of JavaBean:

Page range-> the lifecycle can only be in one page. You can only access the JavaBean on one page. When you refresh the page, the original JavaBean instance is deleted, generate a new JavaBean instance.
The request range-> has a lot to do with the request object. In addition to the entire page, the access range also includes pages contained by Action elements <jsp: include> and <jsp: forward>, that is, both the original page and the contained page can access the original JavaBean instance.
Session range: In a connection, you can access the JavaBean in a connection. (when you access a webpage in a browser, a connection is established, at the same time, a session object representing the connection is created ).
Application Scope: The maximum lifecycle. As long as the Web server is not restarted, JavaBean will always run on the server. Therefore, this JavaBean instance can be used on any page.

I hope this article will help you with JSP program design.

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.