As I said earlier, JavaBean is the implementation: separate the HTML code from the Java code, in the HTML only need to call the Java code on the line, this is called JavaBean.
Now let's share a specific example-read the database, below the specific code + comment
First of all, let's look at JDBC (see another blog for more information on JDBC Programming Basics) directly connected to the database displayed on the page:
This is the first to share the JDBC programming connection database, here I write directly in the JSP.
Good! Here we use JavaBean programming to achieve the same functionality:
The first step: Write a Java class, my JavaBean package defines a Studentdao class
Here I define three functions: query, add, delete, perhaps useful to everyone, here only use the query function, the other functions using the same method.
Step Two: Now write a JSP page to display
Completed, two methods have implemented the same function, the database of students to display the information.
Summary: Using JavaBean to separate the Java Code and HTML code, we see in the client JSP page only a few concise statements, and the implementation of the function is performed on the server side, the client to the server to the JavaBean execution, The server then returns the results of the execution to the client, the entire process client sees only a few simple lines of code in the page, this is the server and the client is separated, and later I will share to you the Servlet programming implementation of the server control layer, then a complete MVC three layer framework is implemented.
For some of these issues, welcome friends to comment, a lot of comments, interested we can discuss together.
JavaBean Programming Ideas-Read database information