Strutcx Introduction

xiaoxiao2021-03-06  89

============= Strutscx ============= Strutscx is a Struts framework, which belongs to the source of source code, rooted in pure XML and XSLT technology. Support multiple languages. With strutscx, we can easily generate HTML, XML, PDF, etc. in a variety of output formats, and Struts is the ideal support technology that performs such XSLT conversion.

Strutscx allows us to save, output content in different languages ​​and coding, easy to handle Chinese, English, German, French, Spanish and Korean, Arabic, Russian, etc. with Strutscx.

First, simply review struts

Struts encourages the system to build applications in Model 2. Model 2 is a variant of MVC basic design mode. The advantage of the MVC design mode is that it makes the modl, view, and all parts of the Controller relatively independent. Struts assembles an ActionServlet, ActionMapping, and a variety of Action classes in a central location to process all incoming httpservletRequest. ActionServlet distributes each incoming HTTPServletRequest to the Action class, and the ActionMapping object can be controlled by struts-config.xml configuration file, which tells how to distribute requests.

Controller's function: coordination between clients, view, and model, arbitration. Only Controller will contact Model and View, which is like a switch, while Model and View will not communicate directly, and Model, View and Controller are separated. This is the key to successfully use Struts.

Explanation: All Controller's logic should be placed in the Action class, and communication with other layers of the application can be performed here. Although we can put business logic in Controller, but generally don't do this. The components of the Model section should be changed because these components are a place that truly processing data. Saving data to the database should also be one of the modes of Model.

When Controller handles a httpservletRequest, it forwards the request to View. The only task of View is to express data. In Struts, View generally uses JSP technology.

In Struts, all communications between Controller and View are indirect through httpservletRequest, httpsession and servletContext. For these operations, the preferred technology is that the servlet, and struts will pass HTTPSERVLETREQUEST to servlet - or JSP, but servlet The container will automatically convert JSP to servlet.

Second, Struts and JSP limitations

As an open frame, Struts allows to construct views using techniques other than JSP. When considering improving the View technology in the Struts application, people first think of often use other servlet technology to replace JSP, such as XSLT or XSLT under servlet management.

Figure 2 depicts the case where JSP is applied in the STRUTS frame. View consists of JSP custom tag libraries and JSP pages, where the ActionForm class is a ValueObject object similar to JavaBean, with SET and GET methods for saving customers. According to the Struts's MVC concept, ActionForm is located between View and Controller's intermediate zone. Struts provides a set of complete dedicated tags to access data in Actionform from JSP. Third, XSLT advantage

As a formal standard of W3C, XSLT provides a flexible, powerful tool for converting XML data into any XML format such as pure text, PDF, HTML / XHTML, WML, VoiceXML, etc. XSLT processors, such as Xalan and Saxon, perform conversion through XSL style, the XSL style itself is actually an XML document.

The XSL style defines a rule that converts XML data, and the XSLT processor implements conversion in these rules. In the XSL style, we can use XPath expressions to select a part of the XML document in a compact and efficient form. The basic idea of ​​XSLT / XPath is to separate XML data content and its expression in order to easily output the same data (or format) to meet the needs of various display devices. That is, for each of the different output formats without changing the input XML document, only the corresponding XSL style is required. For Struts applications, this means:

• Store (description) all data in a single XML document.

• With the help of the XSL style, convert the XML document into any data format.

Of course, the XML document can be generated in memory, do not have to have files saved on the disk. For example, an XML document is created in the form of a Java object, and then processes directly with the XSLT processor to greatly improve processing speed. Four, strutscx: plus XSLT Struts

Strutscx combines the advantages of Struts and XSLT together, which replaces the JSP generated by XSLT, but the Struts's Controller and Model are retained.

In View, the goal of Strutscx is no longer JSP, but a servlet, constructed by the servlet, constructs an XML document, and converts the XML document with XSL style. If there is an actionform bean, the Action object copies it to HTTPSERVLETREQUEST, and then also added to the XML output document. Similar to Struts, StrutsCX action is also a performance layer and other layers of a web application or J2EE application, such as a business layer.

Strutscx and Struts Different performances are in the following aspects:

· In View, StrutSCX is using XSLT instead of JSP.

· The internationalization of the application is no longer achieved by Java resource bundle, but is achieved by pure XML technology.

· Strutscx does not need to use any tag library to output an error message, which uses W3C standard technologies such as XML and XSLT / XPath.

Although Strutscx and Struts have many different, we can also combine Strutscx and existing Struts applications. In fact, Strutscx is just a giving up some standard Struts technology, in order to XML, XSLT, and XPath.

5. StrutscxServlet conversion principle

In Strutscx, XSLT conversion is completed by StrutscxServlet and its several secondary classes, including StrutSCXDocumentBuilder and StrutscXTransformer. StrutscxServlet controls the conversion work in the following: • Construct an XML document with the help of StrutsCXDocumentBuilder.

· Pass the document to StrutscXTransformer, perform conversion.

StrutsCXDocumentBuilder gets the information you need to create an XML output document via HttpServletRequest, HttpSession, and ServletContext, all of which are completed by a unique common method Createdocument. Struts' action checks the information in httpservletRequest, httpsession, or servletContext, which is dependent on the best location for saving this information. The XML Output Document created by StrutSCXDocumentBuilder contains the following information:

• Integration Tier's data: Database data, data from EJB, or data from other XML files.

· One (optional) Actionform Bean, which saves the status information of the client.

• One (optional) ActionerRors object, contains an error message for Struts.

· Strutscx's resource properties, it is used to replace Java resource bundled information under Strutscx.

· The data of HTTPSERVLETREQUEST.

· The data of httpsession.

转载请注明原文地址:https://www.9cbs.com/read-104933.html

New Post(0)