As the servlet prints html code in the middle of the class, it is very troublesome to write the code and is not easy to maintain. sun launched jsp.
But does this mean that we cannot output html code in the bean in the jsp + bean architecture?
Please refer to the webmaster's opinion:
What is encapsulated in the bean is not to encapsulate all printed html statements. For many local similar things, it will be better after encapsulation.
For example, in a simple example, the system generally needs to read some fields from the database and then display them, and requires separate functions. If all the fields are written in the jsp file, there are too many codes, and there is not much difference with asp, which is inconvenient to maintain.
Take the B2B systems I have developed for example, a large part of them are similar, such as product display, information display, and order display. Writing a bean can encapsulate data browsing pages and other functions, you only need to pass several field names.
<Html>
<Head>
<Title> </title>
</Head>
<Body background = "images/bg_flower.gif">
<Jsp: userBean id = "bean"...>
<% Bean. setField ("username, sex, hompage..."); // pass the field
Bean. setTable ("tablename"); // name of the table to be uploaded
Bean. printall (); // call the printall method of bean to display data and separate data.
%>
</Html>
In this way, the development efficiency is very high, no matter how many pages are easily handled. To add a new page, I just need to modify the field name and table name, there is no need to use a large number of statements to read, split, display, and other data, and the logic is quite clear.
Disadvantages: slightly reduced flexibility
Advantage: however, maintenance and management are easy. If you think that you have missed the separate navigation function before, you don't need to change dozens of hundreds of JSPs, and the points in them also show the code. It's easy to modify the printall method of a bean.
I don't know whether it is clear. I think all html statements, like the previous servlet, are output in the class and are messy, however, the separation of logic and ui in jsp does not mean that the print statement cannot be written in the bean at all. Sometimes the print part of the code in the bean will produce better results !!