JSP: usebean beanname

Source: Internet
Author: User
<JSP: usebean> tagged beanname attribute: Specifies the name of the serialized bean.
How can this problem be solved?
It is best to give an example. // ================================================ ========================================================== ============== The bean that can be saved:

Package test;

Import java. Io .*;

Public class firstsavebean implements serializable {

Private string name;

Public firstsavebean (){
}

Public String getname (){
Return name;
}

Public void setname (string name ){
This. Name = Name;
}

}

Related JSP pages:

<% @ Page import = "Java. Io. *" %>
<JSP: usebean type = "test. firstsavebean" id = "TB" beanname = "test. firstsavebean"/>

<JSP: setproperty name = "TB" property = "name" value = "killmm"/>
The following begins to save the object TB to/WEB-INF/classes/test/TT. Ser, pay attention to the suffix name.
<%
String P = "/WEB-INF/classes/test/TT. Ser ";
P = application. getrealpath (P );
Fileoutputstream Fos = new fileoutputstream (P );
Objectoutputstream OOS = new objectoutputstream (FOS );
Oos. writeobject (TB );
Oos. Close ();
%>
Start to use object tb1 to get objects from TT. Ser.
<JSP: usebean type = "test. firstsavebean" id = "tb1" beanname = "test. tt"/>
<% = Tb1.getname () %> // ============================================ ========================================================== =====================< JSP: usebean> ID attribute? For example:

<JSP: usebean id = "mybean" class = "mypackage. mybean" Scope = "session"/>
This statement is equivalent
<%
Mypackage. mybean = new mypackage. mybean ();
%>

The difference is that the last scope attribute determines the bean survival range. Specifically, when processing this tag, if the bean instance with the same ID is found in the specified scope object, such as the session here, in fact, this bean instance will be used in the later part of the page. If it is not found, a new bean instance will be created and registered to the specified scope object, such as the session here, for other JSP pages or requests of this scope.

The so-called "Name of a serialized Bean" is translated into a serial port. In fact, he wants to say that JavaBean can be serialized by default, or serializable interface is implemented, this attribute is used to specify the name of a serialized bean.

Do you understand?

// ================================================ ========================================================== ==================== Upstairs, the answer is not what you ask... However, the name of the serialized bean is correct in the subsequent sections.
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.