Real-time data verification is one of the major advantages of AJAX technology. By applying this technology, the struts verification framework will enhance struts MVC and bring Web applications closer to desktop applications.
This verification framework is used to verify fields. There are many ways to verify on Web applications. These methods can be divided into two types: server-side method and client-side method. The Struts verification framework is one of the best Java-based Web application environments. It can configure the application by using server-side authentication and error messages. This error message is displayed in the call verification process when processing the request. It can also perform client verification, the method is to use the JavaScript on the request page.
AJAX is a JavaScript technology that can call servers asynchronously and obtain XML documents. This type of documents has become very popular recently. One of its purposes is real-time data verification.
This article focuses on Using AJAX to enhance the existing struts verification framework. You must develop several components such as controllers) to select a verification framework and present messages in a specific format for the client) and the tag library to process error messages ).
Prerequisites
A Windows system with Eclipse and Tomcat application server is required. Make sure that the MSXML 3.0 ActiveX object has been registered in the operating system. Struts Library (http://struts.apache.org) and JDOM Library (www.jdom.org) are also required for XML Development see Figure 1 and figure 2 ).
Figure 1
Figure 2
Server scenario
StrustsActionServlet
We must expand from org. apache. struts. action. actionServlet class to obtain the servletMapping variable, which stores information about how to format the extension to the action path in the browser address form for the intent class. When adding code, we must configure web. xml as the Web application descriptor of the application server.
The web. xml configuration is as follows:
...
action
net.sf.struts.servlet.StrutsActionServlet
...
action
*.do
...
|
The Java code of StrutsActionServlet is as follows:
public class StrutsActionServlet extends the ActionServlet.{public String getServletMapping() {return this.servletMapping;}} |
AjaxValidationRequestProcessor
To support the existing Struts framework in step 1, we must extend the RequestProcessor from the Struts software package. We must customize this request processor, because we must determine how to verify by using the existing Struts framework or the AJAX concept ), it is also because we will formulate a contract between the server and the client about how to interpret the message. In terms of message presentation, we will use XML format, which is a good media message transmission format. The XML format of the application is defined as follows:
XML Format
Description
- Identity is the client JavaScript used to know where a message will be placed.
- Description is the result after an error message is displayed on the server.
First, we need to obtain the servlet ing configuration from the Web descriptor before continuing the process ing. After this process is called, the application prepares a form instance, which inherits from the AjaxForm class. This process manages AJAX verification and should be checked to ensure that requests from the client do not use the struts verification framework. Other processes executed during the request process are process filling used to collect information sent from the client to the action form) and process verification by using the existing Struts verification framework that already exists in the method of the parent class TilesRequestProcessor of AjaxValidationRequestProcessor ).
The verification process from TilesRequestProcessor calls all Validation Based on the struts verification framework and stores action errors to requests. We need to carefully analyze Action Errors and generate XML message verification, which will be sent to the client. Because we want to change the behavior patterns that support verification, the verification process should check the indicators of the verification framework used, as shown in figure 3 ).
Figure 3
Use JDOM as the processing engine to generate XML messages. 4. If the process verification is called and the verification framework has the same conditions as the AJAX verification framework, the process continues to populate the error message and build XML message verification.
Figure 4