Views on the advantages and disadvantages of printing html in bean

Source: Internet
Author: User

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

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.