Danh mục

XML, XSLT, Java, and JSP: A Case Study in Developing a Web Application- P4

Số trang: 50      Loại file: pdf      Dung lượng: 1.96 MB      Lượt xem: 18      Lượt tải: 0    
Jamona

Xem trước 5 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

XML, XSLT, Java, and JSP: A Case Study in Developing a Web Application- P4: Là một nhà phát triển Web, bạn biết những thách thức trong việc xây dựng các ứng dụng mạnh mẽ trên nhiều nền tảng. Tạo các ứng dụng di động trở nên thật sự có thể bằng cách sử dụng Java cho code và XML để tổ chức và quản lý dữ liệu. "XML, XSLT, Java, và JSP: Một trường hợp học" sẽ giúp bạn tối đa hóa khả năng của XML, XSLT, Java, và JSP trong các ứng dụng web của bạn....
Nội dung trích xuất từ tài liệu:
XML, XSLT, Java, and JSP: A Case Study in Developing a Web Application- P4132 Chapter 6 bonForum Chat Application: Implementation Using Xalan-Java 2 Instead of Xalan-Java 1 The bonForum release with this book was developed before a stable release of Xalan- Java 2 was available. It turned out that the part of Xalan that we use (XSLT transfor- mation) was among the most reworked parts of the Xalan product as it went to version 2. Here is what the version 2 readme.html says: Given the scope of the redesign, the changes with respect to Xalan-Java 1.x are global in nature …. Xalan-Java 2 implements the TraX (Transformation API for XML) interfaces.The product of extensive open-source collaboration by mem- bers of the XML developer community,TrAX provides a conceptual framework and a standard API for performing XML transformations. Fortunately, the changeover to Xalan-Java 2 did not have a major impact on the design of bonForum—it requires only a somewhat different way to create and use an XSLT processor—so the input and output of that processor will remain the same. For infor- mation about using either Xalan Java 1 or 2 with the bonForum project, please refer to Chapter 4, “XML and XSLT: Xerces and Xalan,” Section 4.5, “Installing Xalan.” Also, check for the latest bonForum information at www.bonForum.org. Xalan’s XSLT Servlet At the time we were developing our XSLT custom tag, there was no XSLT servlet in Xalan.Today, we may be tempted to solve the XSLT requirements of our JSP tag by having it access the XSLT servlet that is now provided with Xalan.We recommend that you try that approach in similar situations.We tried again, with Xalan 2.0.0, but it still had the old documentation for the Xalan-Java 1.2.2 servlet, although it has changed drastically, including the name of the servlet. Now, with Xalan 2.0.1, the servlet sample is a very useful resource. Relative to the root folder for either Xalan- Java 1 or Xalan-Java 2, look for the XSLT servlet documentation at /docs/samples.html#servlet. JSP Scripting with Java Code We found some code in the Xalan sample TransformToDom that looked promising. We decided to put some similar code directly on a JSP, using scriptlets, just to test it. After it was working, we would encapsulate it in a tag class.The details of that code are discussed in section 10.6, “XSLT and the TransformTag Class,” of Chapter 10. We had hit upon perhaps the best procedure for developing the Web application. Developing and testing code directly on a JSP is fast and simple. After it works, you can move it into a separate class, which makes the JSP simpler and enables you to reuse the code elsewhere.We do this only to speed up development; the code usually doesn’t belong in the JSP servlet and needs encapsulation in its own object. XSLT from a JSP Custom Tag Our JSP custom tag for choosing an Actor-Action-Thing command was already send- ing three generic attributes as arguments to a Java servlet method. It was an easy step 6.1 Building the bonForum Web Chat 133to alter that testbed tag so that it could function also as an XSLT processor.The codethat we had used to test our JSP scriptlets was further developed on our chameleon tagand finally found a home in the TransformTag class.With it, we could do the follow-ing on our JSP: Actually, the type value shown is a rather late addition.We now use type attribute val-ues to select XSLT processes. Current acceptable values are “Xalan Java 1” and “XalanJava 2”.There is also a session attribute called “xalanVersion” which can be set to anyacceptable value for the type attribute. One way you can set that session attribute is byincluding something like the following HTML form (JSP or otherwise) that isPOSTED to the BonForumEngine: Apache Xalan Version? Xalan-Java 1 Xalan-Java 2 The BonForumEngine servlet will set the session attribute from the request parameter.The tag class will get and use that session attribute if a value of xalanVersion is usedfor the type attribute in the custom tag on the JSP. Do not worry if the details are notclear at this point, more will be said about all this later. The output of the XSLTprocess need not be HTML—it can be XML, for example. It can also go to a customscripting variable named output, which it does when the outDoc attribute is set tooutput or outputNormaliz ...

Tài liệu được xem nhiều: