Using Javabeans in jsp pages mainly involves three jsp action elements:
(1) Instantiate Javabean. The jsp action element
<pre class="brush:php;toolbar:false"><jsp:useBean id="name" scope="page|request|session|application" class="className"/><pre class="brush:php;toolbar:false">
The id attribute is used to set the name of the Javabean. The id can be used to identify the same jsp page. For different JavaBean component instances used, the class attribute specifies the path for the jsp engine to search for Javabean bytecode, which is generally the Javabean class name corresponding to this Javabean. For example: com.company.UserEntity; the scope attribute is used to specify the life cycle of the Javabean instance object and is also the effective scope of the Javabean. The value of scope can be page, request, session and application.
For example:
<jsp:useBean id="user2" scope="page" class="com.communal.UserEntity"></jsp:useBean>
id="user2" is the name or identifier of the specified Javabean, used for the name of the class instance, scope="page" represents the Javabean Scope, page indicates that it is only available within the scope of this jsp page, class="com.communal.UserEntity" indicates the class name of the Javabean
(2) Accessing the properties of the Javabean. After using
<jsp:setProperty property="propertyName" name="name" value=“string”/>
name is used to specify the name of the Javabean. This Javabean must first be instantiated using
<jsp:useBean id="user2" scope="session" class="com.communal.UserEntity"></jsp:useBean> <jsp:setProperty property="*" name="user2"/>
This is a powerful function of Javabeans: when the value of the property attribute of the
<jsp:getProperty property="propertyName" name="BeanName" />
Among them, name specifies the name of the Javabean. It should be noted that the Javabean component object specified by name must have been used.
Javabeans exist on the server as instance objects of a certain class, so using the
<%=beanName.getPropertyName()%>
The above is the detailed content of How to introduce beans using jsp. For more information, please follow other related articles on the PHP Chinese website!