29 notes for jsp development technical applications

Source: Internet
Author: User
Tags what interface

JSPThe technology uses Java programming language to compile tags and scriptlets like XML to encapsulate the processing logic for generating dynamic web pages. The web page can also access the application logic of resources on the server through tags and scriptlets. JSP separates webpage logic from Webpage Design and display, and supports Reusable Component-based design, making Web-based application development fast and easy. The following are 29 notes for jsp development technology applications.

1. The server must provide verification of input data correctness. The Javascript verification on the client can be absent. This is based on security considerations, because Javascript is easily bypassed, and client verification is added only to reduce server pressure and make the interface easier to use.

2. Use the Session appropriately. Do not place large sets of objects in the Session to avoid excessive memory consumption, because many users will generate many sessions during access. Request should be used for parameter transmission as much as possible. Familiarity with HTTP helps you better understand the mechanisms of sessions, cookies, and requests.

3. On the page with paging query interface, try not to use the post method to pass Parameters. parameters passed by POST cannot be seen in the address bar. After refreshing, a prompt for resubmitting the form will be displayed. When using the get method to pass Parameters, note that the URL length cannot exceed 1 K.

4. The layers should be clear. Currently, we can divide them into three layers: ViewJsp, FreeMarker, Action, BeanService, and DAO, namely the display layer, business layer, and data layer. The record set ResultSet, which can only appear in the DAO layer, cannot appear in the BeanService) layer. Similarly, the HttpServletRequest, which can only appear in the View layer, should not appear in the BeanService) layer. This is not absolute.

5. Try to use simple SQL to avoid two tables and multi-table join queries. Multi-table joint query will cause a significant increase in database pressure, which is not conducive to caching some records in the memory, and the code reusability is also difficult to improve.

6. To avoid executing methods such as findXXById in a loop, it is better to execute methods such as findXXByIds to retrieve records to Map at one time. This method should be provided for most tables with actual objects.

7. If you use the most primitive jdbc programming, pay attention to the correct release of resources. The new Statement or ResultSet in the loop should be closed in the loop.

8. When writing an SQL statement for query, you must be able to determine whether the SQL statement has used an index to avoid full table scan and add an index if necessary.

9. before writing a method, first check whether there are methods with the same functions or similar functions, especially tool methods, which have already been written to avoid repeated code generation, process repeated codes in a timely manner. If a piece of code is repeatedly used two or more times, you can consider writing a special method to put this piece of code. Similarly, constants used multiple times should also be specifically defined.

10. in a method, there may not be only one return. If a return result is returned as soon as possible, there is no need to add nested layers. This will lead to poor code readability, but it cannot return too much, the code looks comfortable.

11. don't be satisfied with the ability to write DAO and BeanService code skillfully. In comparison, if the background is supported by a mature framework, coding is not too difficult and is not worthy of self-satisfaction, this is a basic requirement for Java R & D engineers. Properly cultivate the front-end coding capability and learn to use Dreamweaver. Do not underestimate the interface or consider it a matter of interface design. The interface is software for the user. It is no harm for you to learn to compile CSS and adjust the interface.

12. Clearly define the scope of Java and javascript, and clarify what they can do.

13. The strange phenomenon is generally caused by some low-level errors. If you haven't found any result for a while, let others check it.

14. Do not use a field that may be modified as the primary key, which will make updates to relevant records a big headache.

15. If you are forced to use a hybrid operation between Hibernate and jdbc, do not use Hibernate for complex queries and statistics. If Hibernate is not used well, the benefits will be very limited.

16. the database is often read, but it is rarely modified. If such data is read to the cache such as OSCache in the memory, it should be updated on a regular or trigger basis to reduce the number of reads to the database, improve performance.

17. when coding, you should pay attention to the impact of the deployment environment, including the path differences caused by different operating systems, time differences between application servers and database servers, and the Internet may be deployed on multiple servers, the objects put in the Session must be copied to implement java. io. serializable interface.

18. Try not to write too much code on jsp. It is very important to keep jsp clean and tidy. It is not a mess to open it with Dreamweaver, and it cannot be seen at all what interface this is.

19. currently, our projects generally use Spring to manage database transactions, and are generally configured in BeanService), that is, the business layer. Be sure to maintain transaction integrity, do not scatter operations that should be put together on the Action layer. Related update operations can be considered as a transaction, such as adding a parent and updating whether the student has a parent field.

20. In Spring configuration, for some method operations that require independent transactions, such as generating a primary key, the method should be declared as an independent transaction ROPAGATION_REQUIRES_NEW. If a checked exception is thrown in BeanService, the transaction will not be rolled back by default and must be declared, such as <prop key = "*"> PROPAGATION_REQUIRED,-PassportException </prop>.

21. When referencing other beanservices in a BeanService), try to reference BeanService) instead of DAO. Because other Bean services) often encapsulate DAO operations and further improve, such as adding verification, so these methods should be reused, you do not have to reference the DAO method to override these operations.

22. Add comments to the interface definition of BeanService at least to help others reference the method you write.

23. Make good use of Map, List, and Set in the Collection framework. In particular, HashMap, ArrayList, and HashSet are used most often. These classes are the basis for multiple data operations, and they are not thread-safe.

24. The page that is running fast now may slow down as the data volume increases, so you should be aware of the reason that the page may slow down, rather than looking fast now. Most of the factors affecting the speed are the pressure on the database. It is not common to spend a lot of time on java code execution.

25. Avoid unnecessary jumps. If the page is executed fast enough, the loading progress prompt page in the middle is unnecessary, which will make the user feel flickering.

26. Pay attention to the file size of the page. Not every user's bandwidth is ideal. The file size is smaller and faster, and it always feels better.

27. Do not modify users' browsers, such as hiding their address bar, menus, and right-click menus, which may cause some users' dislike. Try not to use the pop-up window, which may be blocked.

28. Website permission control should at least ensure that users with access permissions can access the page. Hiding links and other methods is not safe. If users cannot see them, it does not mean they are safe. To control permissions, try to use the interceptor mechanism in the framework instead of writing the permission control code everywhere. The filter should not be used too much, not only because the scope of the filter is difficult to control, but also may cause confusion of page execution results, and it is difficult to troubleshoot errors.

29. In most cases, the relative path is used on the page to ensure that the Action path level is consistent with that on the page, so that the application can be published in various directories.

As we all know, JSP technology is a bit similar to ASP technology, it is in the traditional web page HTML file (*. htm ,*. insert the Java program segment (Scriptlet) and JSP tag in html to form a JSP file (*. jsp ). Web applications developed using JSP are cross-platform. They can run both on Linux and other operating systems. I hope this article will help you.

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.