Struts Quick Start (4)

zhaozj2021-02-11  173

Use an actionforward navigation

The ActionForward object is a configuration object. These configuration objects have unique identifiers to allow them to retrieve them according to meaningful names such as "Success", "failure". The ActionForward object encapsulates the forward URL path and is requested by the processor to identify the target view. The ActionForward object is built from element located in Struts-Config.xml. Below is an example of element examples of Struts, belonging to the range of element.

Type = "packagename.editcustomerProfileAction"

Name = "CustomerProfileform" Scope = "Request">

Based on the result of executing the executor's EXECUTE (...) method, when a value matching the value specified in the element, the next view can be used in the Execute (...) method for convenient Method org.apache.struts.Action.ActionMapping.FindForward (...). The ActionMapping.FindForward (...) method provides an ActionForward object from its local range and from the global scope, which returns to the RequestProcessor to call the next view in RequestDispatcher.Forward (...) or response.sendredirect (...). When the element has the redirect = "false" property or the redirect property does not exist, RequestDispatcher.Forward (...) is executed; when redirect = "true" is, the sendRedirect (...) method will be called. The following example exemplifies the usage of the redirect property:

In Struts-Config.xml element also provides another feature to control the Name property of the element to be interpreted. This element is used in the INPUT property in the combination element, as shown below:

Type = "packagename.editcustomerProfileAction"

Name = "CustomerProfileform"

Scope = "request"

INPUT = "Profile">

The above element contains an input attribute and a forward name; the forward name is the same as . In the configuration described above, when ActionForm.Validate (...) returns a non-empty or non-NULL ActionerRRORS object, requestProcessor will select elements, its name attribute and element INPUT attribute have the same value This behavior is a standard behavior that is confirmed by confirming errors unless the subclass replaces RequestProcessor. Declare the element below, when ActionForm.Validate returns a non-empty or non-NULL ActionerRORS object, the Input property provides a forward URL instead of the name of ActionForward. This is the default configuration when the InputForward property does not exist.

Progressive points to a specific path, if there is no "/" in the path. For advanced or redirects, the URL in Struts is established internally by RequestProcessor with the following structure.

If redirect = true, the URL establishes such as / contextPath / path because the URL is explained in httpservletresponse.sendredirect (...) with "/" starting relative to the root directory of the servlet container.

If redirect = false, URI established, such as / path, because servletContext.getRequestDisptacher (...) uses virtual directory related URLs.

Capture form data

The JSP specification provides a standard approach to extract and save form data from JavaBean when requested, using and . However, this method has led to a strong coupling between the representation layer and Javabeans; in addition, HTML document creators have to understand such components and know that they correctly usage in the page. Because JavaBean can be used by the tab or is established and placed in another server component, it is likely to share lifecycle management issues in JavaBeans in different components. Struts provides a mechanism to extract, save, and verify form data; at the same time it overcomes the shortcomings of and . Here is a new and element.

the above example of mapping a JavaBean packageName.customerProfileForm type name = customerProfileForm (unique identifier) ​​to a element Name = CustomerProfileform; requests the processor to be submitted to the requested path / EditCustomerProfile uniquely identifies. This form is established and used in semantics to use the following static model:

Pattern

First, we will browse these forms to process semantics until you use simple JavaBeans objects. These objects are implemented as an Actionform object. We will then discuss form processing using the DynaActionForm object, which can support the dynamic collection of attributes when requested.

Ice cloud translation, please let us know.

IceCloud@sina.com

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

New Post(0)