js| Code | specification. The entire jsp/jsp bean presentation layer should be as thin and simplistic as possible.
。 Remember that most jsps should be read-only, and the page bean provides the model.
。 You should design JSP and JSP beans together
。 Remove the business logic from the JSP as far as is reasonably possible. HTTP-specific logic (for example, processing of cookies) belongs in the bean or support class, not in the JSP.
。 Try to put the conditional logic in the controller rather than in the view.
。 Use a standard naming convention for JSPs, included files, JSP beans, and classes that implement extension tags. Such as:
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 page introduction directives in your JSP. The import directive prompts the class to be materialized instead of the JSP Bean's instantiation:
No: <%@ page import = "com.java.util.*"%>
And with: <% java.util.List l = new java.util.LinkedList (); %>
。 The JSP should not directly access the request parameters. The bean should perform such a process and output the processed model data.
。 The JSP should not access the property file, or use Jndi. The bean can access the property.
。 If the JSP bean has all the properties that cannot be mapped from the page request, try to set the property in the <jsp:useBean> tag.
。 You should avoid designing pages that display both the form and the results.
。 Avoid code duplication in your JSP. Put the functionality you want to repeat in a contained JSP, Bean, or markup extension so that it can be reused.
。 JSP beans should never create HTML
。 You should avoid using OUT.PRINGLN () in JSP to generate page content.
。 The JSP layer should not directly access data, including JDBC database access and EJB access.
。 In length, scriptlests code is best not to exceed 5 lines.
。 In addition to JSP beans, a JSP should not instantiate complex, writable objects. If so, it is possible to execute inappropriate business logic in the JSP.
。 A JSP bean should not contain a large amount of data.
。 If you use the <jsp:forward> and <jsp:include tags, and you must use a simple type of value to communicate with an external page, you should use one or more <jsp:param> elements
。 Custom tags should be used where proper logic is removed from the JSP.
。 The <jsp:forward> tag should be used cautiously, and it is an equivalent goto in the JSP.
。 You should use hidden annotations to prevent the output of HTML from being too large.
。 Avoid exception handling in JSP
。 You should use an error page in each JSP file to handle exceptions that cannot be recovered from.
。 In the JSP error page, use an HTML annotation to display exception tracking information that is passed to the page.
。 Use the Jspinin () method and the Jspdestroy () method only if you are able to gain performance benefits. Getting and discarding resources is a matter of JSP beans and labeling the processor, rather than being responsible by the JSP.
。 If there is no good reason, do not define methods and internals within the JSP.
This digest is from Java Coding specification.