Application of XML in the development of B / S architecture
Traditionally, we use JSP Bean to develop user interfaces, hereby introducing a way to use XML XSLT to replace JSP
motivation:
1. The JSP constructing page is too painful. The code embedding page leads to bloated pages, logic is complex, and it is difficult to edit.
2. Programmer and artist interface must be precisely defined. Complex nested outputs must construct complex display classes as an interface.
3. Debug JSP must wait until the end of the program is ended to see the effect.
3. The debugging JSP is extremely low, and a little small modification will cause the JSP recompilation.
New XML solution:
1. A servlet is unified management. Accept the URL request, map to the corresponding program bean.
2. The program bean generates only XML, and the corresponding XSL converted to HTML by the servlet unified.
benefit:
1. JDK1.4 has comes with XML API and XSLT, and supports XSLT 1.0 standard. IE6 also supports the same standard.
2. The Demo XML used before the development first creates the interface, and the programmer's output must conform to this format. The US is based on this format to make XSL. Interface visualize, clearly defined.
3. As long as the interface XML is defined, there is hardly need to be jointly debugged on both sides. Art uses interface XML and IE6 to see the effect directly.
4. Programmaker only guarantees whether the output XML is in line with the interface, intuitively doing textual comparisons.
5. A large number of page reusable parts can be easily abstract, in the XSL file, INCLUDE / IMPORT in the XSL file. Highly reuse, standardization.
6. Write XSL to use Template, clear structure, easy to modify, write the page to a wooden, no longer a layer of JSP.
7. For different terminal devices, different XSLs can be customized, which is convenient to support mobile phones, PDA ...
8. Using the support for XML in the program, such as SQL2000, you can directly generate XML results without complex programming.
harm:
1. Because XSLT conversion is to be performed, the server workload is slightly increased.
The following is a simple example of several key links: ============== x ======================== / ** * XML is String * XSL from the file Read * Directly Write Response * /// Import Javax.xml.Transform. *; // Import Javax.xml.transform.Stream. *;
StreamSource XML = New StreamSource (Xmlsource); streamsource XSL = New StreamSource (xslFileName);
Response.setContentType ("text / html; charset = UTF-8"); streamResult result = new streamResult (response.getwriter ());
Transformer Trans = TransformerFactory.newinStance (). NewTransformer (XSL); Trans.SetOutputProperty ("Encoding", "UTF-8"); Trans.Transform (XML, Result);
================== interface XML file sample ============= XML version = "1.0" encoding = "UTF-8" ?> xml: stylesheet type = "text / xsl" href = "xxx.xsl"?>