JSP coding Specification

Source: Internet
Author: User

. The presentation layer of JSP/jsp bean should be as thin and simplified as possible.

. Remember that most JSP pages should be read-only views, and the page bean provides the model.

. JSP and JSP bean should be designed together

. Remove the business logic from the JSP as reasonably as possible. The specific HTTP logic (such as Cookie processing) belongs to the bean or support class, rather than in JSP.

. Try to put the condition logic in the controller rather than in the view.

. Follow standard naming conventions for JSP, included files, JSP beans, and classes that implement extension tags. For example:
JSP controller xxxxcontroller. jsp
Included: JSP _ descriptivenameoffragment. jsp
JSP page model Bean: <pagename> bean, such as loginbena. Java
JSP session Bena: xxxxsessionbean
Tag class: xxxxtag, xxxxtagextrainfo

. You should avoid using the page introduction command in JSP. The import command will promote the real-name listing of classes rather than the instantiation of JSP beans:
No: <% @ page import = "com. java. util. *" %>
Usage: <% java. util. List L = new java. util. Using list (); %>

. JSP should not directly access request parameters. Bean should execute such a process and output the processed model data.

. JSP should not access the property file or use JNDI. Bean can access attributes.

. If all attributes of the JSP bean cannot be mapped from the page request, you should try to set the attributes in the <JSP: usebean> tag.

. Avoid designing pages that display both forms and processing results.

. Avoid code duplication in JSP. Put the function to be repeated in an included JSP, Bean, or tag extension so that it can be reused.

. JSP beans should never generate html

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

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

. In terms of length, the scriptlests code should not exceed 5 lines.

. In addition to JSP beans, JSP should not instantiate complex readable and writable objects. In this case, it is possible to execute inappropriate business logic in JSP.

. JSP beans should not contain a large amount of data.

. If <JSP: Forward> and <JSP: Include mark> are used, and simple type values must be used to communicate with external pages, one or more <JSP: param> elements should be used.

. Custom tags should be used where appropriate logic is removed from JSP.

. Use the <JSP: Forward> tag with caution. In JSP, it is an equivalent Goto.

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

. Avoid Exception Handling in JSP

. Each JSP file should use an error page to handle exceptions that cannot be recovered from it.

. On the JSP error page, use HTML annotations to display the exception tracking information that is passed to the page.

. The jspinin () method and jspdestroy () method are used only to obtain performance benefits. Obtaining and discarding resources is a task of JSP beans and marking the processor, rather than being handled by JSP.

. If there is no good reason, do not define methods and internal content in JSP.

Related Article

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.