Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Code Optimization with JSP bean

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces JSP bean how to achieve code optimization, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

First, code optimization. The checkpoints are as follows:

1. The entire jsp/jsp bean presentation layer should be as thin and simple as possible.

2. Keep in mind that most JSP should be read-only views, while the page bean provides the model.

3. JSP and JSP bean should be designed together

4. You should avoid using page introduction instructions in JSP. The import directive causes the class to be enumerated instead of jsp

5. Instantiation of bean

6. Avoid code duplication in JSP. Place the functionality to be repeated in an included JSP, bean, or markup extension so that it can be reused.

7. In JSP, you should avoid using out.println () distribution to generate page content.

8. Apart from JSP bean, JSP should not de-instantiate complex read-write objects. If so, it is possible to perform inappropriate business logic in JSP.

9. Hidden comments should be used to prevent the output HTML from being too large.

10. Do not define methods and inner classes in JSP without good reason.

11. Try to avoid using instance variables in Servlet/JSP

12. You should avoid using page introduction instructions in JSP. The import directive causes the class to be instantiated rather than jsp bean instantiated instead of:

JSP should not access properties files or use JNDI. Bean can access the properties file.

14. JSP bean should never produce HTML.

15. JSP bean should not contain large amounts of data.

Custom tags should be used where logic is removed from the jsp appropriately.

17. The link to "return to the previous level" or "back" should not be written as: going back to the previous level using the prev instruction does not necessarily achieve the true fallback effect, there will be abnormal jumps. "

18, it is recommended not to hard-code, especially page links, parameters, text messages, if written in the java file, it will bring a lot of maintenance workload. Our aim is to simplify and minimize the operation of the existing network as much as possible. Try to use configuration files and database tables to implement

II. Business security

1. Remove the business logic from the JSP as reasonably as possible. HTTP-specific logic (for example, handling of Cookie) belongs in bean or supporting classes, not in JSP.

2. The JSP layer should not access data directly, including JDBC database access and EJB access.

3. JSP should not access the request parameters directly. The bean should perform such a process and output the model data being processed.

4. Try to put the conditional logic in the controller instead of in the view.

III. Structure

1. An error page should be used in every JSP file to handle exceptions that cannot be recovered from it.

2. Avoid exception handling in JSP

Thank you for reading this article carefully. I hope the article "how to optimize the JSP bean Code" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report