Bean by fdjerue7eeu


Bean is the acronym for Enterprise Java Bean, a Bean plays the role of the application
material. She includes a functional interface, a life-cycle interface, and a real way to
do it to support the business category.
Java is a description of the software component model, somewhat similar to the
concept of Microsoft's COM components. In the Java model, which can be
infinitely expanded by JavaBean Java program features a combination of JavaBean
quickly through the formation of new applications. For programmers, the best thing is
to JavaBean can achieve code reuse, other procedures easier for maintenance and so
on have very great significance.
For example, a shopping cart program, shopping cart Add to achieve a commodity
such functions, you can write a shopping cart operation of the JavaBean, the
establishment of a public member of the AddItem method, front Jsp file which calls
this method to implement directly. If you later need to consider when adding products
to judge whether the stock of goods, no goods shall not purchase, at this time we can
directly modify the JavaBean's AddItem method to add processing
statement to achieve, so we did not modify the front jsp proceedings.
A simple JavaBean
import *;
public class FirstJavaBean (
private String FirstProperty = new String ("");
public FirstJavaBean () ()
public String getFirstProperty () (
return FirstProperty;
public void setFirstProperty (String value) (
FirstProperty = value;
public static void main (String [] args)
System.out.println ("My First JavaBean!");
If you run this program, will appear the following results:
First JavaBean!
This is a typical representative of JavaBean simple to explain, FirstProperty is one of
the property (Property), the external through the get / set methods can operate on this
property, if you wrote a VB of the class, then this would no longer familiar. Main
method is used to test procedures, write JavaBean Jsp can be added to the program
without first calling, and direct use of main approach to debugging, debugging can be
good after the procedure call in the Jsp.
JavaBean Overview
Users can use the JavaBean functional, processing, value, database access, and other
any Ke Yi 用 java Daimachuangzao packaged objects, Bingju other developers can
be internally of the JSP page, Servlet, Qita JavaBean, applet program or application to
use those object. Users can view anywhere JavaBean provides a copy and paste
function, without regard for any change.
JavaBean development
Initially, JavaBean are intended to be reusable software code packaging standards.
Especially the use of and to help manufacturers develop the integrated development
environment (IDE) to use the java software components. These include such as the
Grid control, the user can drag and drop the components into the development
environment. Since then, JavaBean can be extended to a java web application of
standard components, and JavaBean components framework has been extended for
the Enterprise Edition of the Bean (EJB).
JavaBean Requirements
JavaBean is a java class, is aware of certain coding guidelines, and expand the
flexibility and scope, allowing users to access internal properties and methods.
Through these, JavaBean class can be used in the following ways:
1. In the IDE,, JavaBean functionality allows application developers to browse one of
the methods, even if the JavaBean is being compiled, and can not use the original
source file.
2. In the Remote Method Invocation (RMI) distributed style, this feature does not
sound exciting, but in the next version of Enterprise JavaBean contains, will change
3. In order to JavaBean property values and the state can be saved to disk.
JavaBean Design Considerations
Practical applications, the performance of the former extended object or JavaBean
design is very useful. Often believe that if the provision of information, web
developers will support the functionality to meet the needs of the JavaBean. For
example: HTML to display sensitive data, users can screen the entries, such as
passwords, phone numbers.
Good planning and design of the JavaBean is trustworthy.
Java is different from the SQL null in the null
In view of such a test program:
public class NullTest
public static void main (String [] args)
int I = 0;
/ / Int I = null; / / not a valid initialization
String str = null;
String strZeroOutValue = "";
StringBuffer sb = new StringBuffer ("Null test: String initialized as null
sb.append (str);
sb.append ("\ n String representing a Zero Out Value:");
sb.append (strZeroOutValue);
System.out.println (sb.toString ());
This procedure will produce the following results:
Null test: String initialized as null = null
String representing a Zero Out Value:
In the JavaBean, we will declare the variable I as an int, we have to deal with the
variables related to values, because I have not the default value, int type can not be
initialized to null, if no explicit value int initialized the compiler will prompt an error.
Executive NullTest program, will verify the hollow in the text string is null alternative,
used to display the SQL insert and update. If we need to delete some information, by
deleting the text of the form region, you need to send the database a string of length 0.
Although most of the database will be an empty string as null operations, if we use the
database does not support the handling empty string, we must write additional java
code to create your own SQL insert statement.
For example:
if (test.length == 0)
sb.append ("null");
sb.append (test);
JavaBean's Range:
JavaBean range. Scope is a life-time variables. The range of JavaBean
<jsp:useBean scope="….> signs in the right side of that.
will produce a quick reference to a JavaBean.
Description: jsp server engine will strip <jsp. . . . Tag. And in the
end-user's browser can not display the actual code.
There are four areas of the following: page, request, dialogue, and application.

Scope of the dialogue:
The scope of application of JavaBean dialogue with the main span multiple pages and
time: for example, fill user information. Add information and receive feedback, save
the user page recently carried the track. JavaBean to retain some scope of the dialogue
and the user ID information related to the dialogue. This information comes from the
dialogue temporary cookie, and when the user closes the browser, the cookie from the
client and the server to delete.
Page / request scope:
And scope page request form JavaBean are sometimes similar to the bean, this is
because most of them used to process the form. Form takes a long time to process
user input, usually for the page to accept HTTP / POST or GET request. Another page
and request scope bean can be used to reduce the load on the server large site, if you
use dialogue bean, processing delays may be a lot of resources consumed.
Applications are usually used in server components, such as JDBC connection
pooling, application monitoring, support count, and others involved in the class of
user behavior.
Bean to limit HTML in the production:
In theory, JavaBean will not have any HTML, because this is the jsp layer is
responsible for the work; However, in order to provide some advance preparations for
the dynamic message format is very useful. HTML generated will be marked
JavaBean method returns.
There are some very important things:
1. Do not try to return the HTML in place JavaBean any font size.
Not all browsers are the same. Many browsers can not handle the full font size.
2. Do not attempt to return the HTML JavaBean place any script or DHTML.
Direct output to the page script or DHTML is equivalent to self-destruction, because
some browsers handle incorrect version of the script will crash (very small but there).
If the user of the JavaBean at runtime is a dynamic introduction of complex HTML
language, the user will fall into a debugging nightmare. In addition, the complex will
be limited HTML JavaBean life and flexibility.
3. Do not provide any choice.
If the user browse the page using a different system, can provide a method can be
replaced. </ CA>

To top