How to work with Struts

zhaozj2021-02-16  52

http://jakarta.apache.org/struts/faqs/works.html (I just translated, welcome to reprint and communicate, please indicate the author information before reprinting, thank you) Java servlets is designed to manipulate ( Handle) WEB browser request. Java ServerPage is designed to create a dynamic web page that publishes publicity sites to the online application system. Struts uses a special servlet as "Switch" to transfer requests from the web browser to the corresponding ServerPage. This makes web applications easier to design, create and maintain. The following is a more detailed description of the mechanism and dependence relationship between Struts: l The web application you develop has a deployment description file (web-inf / web.xml) that must be written. This file describes the configuration of your web application, including Welcome Pages (Welcome Pages) (files that appear in the directory), servlets, and mapping of those servlets. In this file, you configure Struts ActionServlet as a servlet that manifes all specified mappings (usually .do is extension). This is the "switch" mentioned earlier. Also in this file, you configure the ActionServlet to use one or more profiles used for Struts itself. In this tutorial, assume that we install the web app under the server / myApp and use the simplest possible configuration. If you need to know more detailed information about deployment descriptors, please read the Servlet specification, this can be obtained at Sun's Java site. l In the Struts profile, you associate the path and your application's control components, like the Action class (for example: "login" => loginaction class). This tells the ActionServlet of Struts, when

http://myhost/myapp/login.do

When requesting, you should call your control components loginaction. Note the suffix in this URL.do. This suffix causes your container (such as Tomcat) to call an ActionServlet, which will see a word "login" as a thing you have to do. When this configuration is referenced, your LoginAction is also executed. l For each action, you can also configure Struts with the name of Resulting Page, which can display the result of the action. The result of the action can have more than one view (usually, there are at least two: one is success, one is failed). Your Action (you write control components) depends on the map name of these "logical" results. It uses some words such as "Success" ", Failur", "OK", "UserinIncompeTnt" to the ActionServlet. Struts system (through the configuration file you write) know how to turn to the appropriate specified page. This is the additional benefits of reconfiguring the Struts XML configuration file for the view layer. From this point of view, Struts knows how to delegate your control components, know what your controller processing is to display. The application's model is completely dependent on you, it is called from your control components. l You may have to associate a Java Bean with an action (or a set of action) in the Struts configuration file. Java bean is used as a Warehouse (Repository), which can communicate in View and Controller layers. These beans will be automatically visible to your control components (like loginAction) and any display pages associated with the controller (Controller). With the help of the Struts system, these Beans will be approved to help confirm that the user enters the correct data in the form. They can be carried by a session, allowing forms (FORM) to span multiple view pages, while Actions are in the controller. Note: In order to make the display layer see these data, you must use some server technology (JSP, Velcity, XSLT) (static HTML does not work). Struts works on the server, so the customer's view must be written there. The client feeds back data through a general form submission (POST / GET) method, and the STRUTS system updates the data in the bean before calling your control components. l In your web application, there will be some pages that are used to express your users will see. These can be a JSP page, a Velocity template, a XSLT page, and more. A set of JSP tags and Struts release package bound, so you can use it immediately, but it is not said that any standard representation technology can be used in Struts. Of course, static HTML files can be used in your Struts app, but they will not get the benefits of full-time dynamic characteristics. In the example of Struts JSP Taglibs, some other packages have made this framework easier to use some of your preferences. For the Velocity Template, there is ViewTools for Velocity for Struts. If you want to use XSLT in your application, you can choose between StXX and Strutscx. These envelopes the standard Struts frame elements look like the indivisible part of the original performance technology.

Struts also makes it easy to mix and match. If you need, you can use JSP, Velocity Templates and XSLT in the same app! Since Struts depends on standard servlet technology, all you should be able to use any Java performance technology in Struts. l Although the focus of the Struts frame is in the controller, the performance layer is an organic part of any application. The Struts JSP tag library includes some normal and struts-specific tags to help use dynamic data in your view. Customer custom JSP tags account for a large part of the STRUTS base code. One of the educated significance is that in the 1.1B3 version, the core Java code for Struts is approximately 28,000 rows, and the Java code of the label library (including tiles) is nearly 41,000 rows. These tags help you bond your view layer and control layer without inserting a lot of Java code in JSP. This makes the page look like an XML file, compared to an ordinary JSP file, which makes web designers easier to handle. This also helps reduce the coupling of control and view. Customized tags are used to create a form (non-displayed and previously mentioned bean), logically point to other pages, then activate other Actions in the web application. There are also some tags to help you carry out internationalization, error message processing, and more. All of these features rely on some methods of your configuration files applied to Struts. What you need to remember is that the mechanism here is only valid when the ActionServlet handling request. Since this happens when your request is submitted and then causes the container to call an ActionServlet, you must ensure that any requests that depend on the Struts are mapped to ActionServelt.

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

New Post(0)