Struts validation framework with Ajax

Source: Internet
Author: User

Real-time data validation is one of the great advantages of Ajax technology. By applying this technology, the Struts validation framework enhances struts MVC and makes Web applications closer to desktop applications.

This validation framework is used to validate fields. There are many ways to validate on a Web application. These methods can be divided into two categories: server-side methods and client methods. The Struts validation framework is one of the best frameworks for a java-based Web-application environment. It is able to configure the application by using server-side validation and error messages, which are rendered on the calling verification process when processing the request, and are capable of client-side validation by using the JavaScript rendered on the request page.

Ajax is a JavaScript technology that makes it possible to call servers asynchronously and get XML documents, a document that has been very popular recently. One of its uses is real-time data validation.

This article focuses on using AJAX to enhance the existing struts validation framework. Several components, such as a controller, must be developed to select a validation framework and to render messages in a particular format (for clients) and tag libraries (handling error message rendering).

Necessary

Requires a Windows system with Eclipse and Tomcat application servers. Make sure that the MSXML 3.0 ActiveX object has been registered with the operating system. The Struts Library (http://struts.apache.org) and the Jdom Library (www.jdom.org) are also required for XML development (see Figure 1 and Figure 2).

Server-side Scenario Strustsactionservlet

We have to extend the class from Org.apache.struts.action.ActionServlet to get the servletmapping variable, which stores information about how to format the extension as a browser address form for the action class. When adding code, we must configure Web.xml as the application server's Web application descriptor.

The Web.xml configuration is as follows:

  ...
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>net.sf.struts.servlet.StrutsActionServlet</servlet-class>
...
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
...
StrutsActionServlet Java代码如下:
public class StrutsActionServlet extends the ActionServlet.
{
public String getServletMapping() {
return this.servletMapping;
}
}
Ajaxvalidationrequestprocessor

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.