<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.