Eight, use the MVC design mode
Of course, other design patterns can be used in JSP, and I often use model-view-controller (MVC) system agencies. MVC can make it easier to build, test, maintenance, and improvement. In JSP terminology, the reality of the MVC architecture is often raised as Model2 (from early JSP specifications). An example of J2EE Blue Book is based on MVC mode.
Read BIN Yang's "E : a pat1" and Govind Seshadri "Understanding JavaServer Pages Model 2 Architecture" get more information about JSP and MVC.
Struts
Struts is an open source MVC implementation, which provides the function of inheriting, modifying, modifying in your application. The basic controller is an implementation as a Java Servlet, which is controlled by a file called Struts-Configxml. When a Struts-based JSP web application is established, most changes are flow control in the struts-configXML file, not its own code.
Implementation of an application that adapts to MVC mode requires an early additional job. However, this pre-investment can get more "reusable and maintenance" code worth rewards. Furthermore, Struts is also worth noting to achieve simplification of the initial work of MVC.
In addition to providing MVC implementation, Struts also provides some valuable custom label libraries, such as the template label library mentioned earlier. The logical tag library contains a custom label for an iterative loop, the IF-THEN-ELSE structure. The HTML tag library is a representative of many valuable custom labels, including Form and custom labels for Struts Form processing, and papers. Read the Struts documentation to get more detailed information about these tag libraries and other tag libraries. Next, discuss the advantages of using these labels.
Nine, use effective label custom libraries
When the label library can be easily and effectively used in a variety of purposes, why does the developers spend time for duplicate development, worrying test, and adjustment? Some sellers provide custom labels for their customers in a free or separate way. But many custom label libraries can be found online, providing a good starting point for finding a potentially useful label library.
Of course, these third-party tag libraries are sometimes bugs, and many developers are used in their application development. Most of these issues are very likely to be discovered, and many custom labels are open source, you can Modify them according to your needs.
I have found that the custom label is worth it. Because these label libraries usually provide general features of most web applications, and learning these tags require only small amount of time investment, reusing existing, effective custom labels can save writing , Debug, test your own custom label time. As mentioned above, many tag libraries are open source. For these reasons, I can easily adapt general behavior to our specific project.
Ten, determine the appropriate XML dependence
Most JSP developers use JSP tags to non-XML syntax. This is partial certification in the JSP syntax reference (listed only the label).
The advantage of using 100% XML according to JSP tags is that the XML verification tool verifies the JSP file to perform DTDs that perform JSP basic syntax rules.
However, JSPs that are currently written or maintained for an XML tag syntax requires additional more work. When the tummy syntax is automatically converted to the XML syntax, the benefits of using XML form JSP will make these work. I look forward to the JSP specification and implementation related to XML form JSP before the label in the form of XML, can be mature. You can read "XML In The JSP Specifications" to get more information about how XML compliments is used in the latest JSP specification.
I am not implying that you can't use XML in the current JSP technology. I just look forward to having a better processing of JSP-XML mapping in the specification of the 1.2 version. However, there are other ways to use two technologies, you can read the article resources for using XML and JSP. 11. Use JSP comments as much as possible
Appropriate notes seem to be the challenge of software developers. JSP or other codes should include comments to describe complex special features, page uses, and other basic information.
Since the JSP allows developers to mix Java, JSP tags, HTML tags in a page, there are a number of methods of annotating JSP pages, and developers should carefully consider which annotation mode. HTML Note is visible in HTML source code compiled via JSP, and the browser is easy to see. On the other hand, JSP comments are not placed in an HTML document created by the JSP compilation process, which cannot be seen as part of the page source code. Java annotations can also appear in the Java block in the JSP file, it is also invisible in the browser. However, in JSP includes Java annotation violates the principles of separation Java, HTML code.
Note is usually a developer that is written or maintained. Therefore, JSP comments should be used unless there is a need to display the situation in the browser.
12. Follow HTML Best Practices
When Java is decomposed from JSP into the JavaBean and custom tag manager, the JSP is composed of JSP tags (including custom tags) and HTML tags. Follow the best practices related to HTML development to make JSP easier to understand and maintain.
W3C has some resources about HTML best practices and verification.
Thirteen, using JSP unusual mechanism
For developers of debug code, a throttle of abnormal stack is extremely important, and software users share a complete exception stack information is extremely less. The lengthy stack information is not very beautiful, and it has increased security risks due to the unnecessary release of unnecessary release. JSP allows developers to capture and process exceptions in the code.
Abnormal information except the stack traces is more useful. JSP can use a session variable to save information that is currently executing the page and operations. Next, if an exception is generated, the exception page will be called, which will simultaneously access the throttle information and the information generated by the abnormal start page. The exception page can be deposited in the database using the Java code in JavaBean or EJB in the Java code, and exception date time information.
Reduce visible error messages Print to the screen while improving security. The exception page only prints simple error messages and possible authentication codes, which enables development to find more detailed exception information in the database. Because of the aesthetic and security reasons, I am more willing to save most of the exception information into the database or plane file rather than printing on the screen. This simultaneously allows an exception to exist, or even when the user exits the application. Note that for normal testing and debugging during development, you should print all of the exception information on the screen.