This article introduces how to add Ajax effects to form verification of struts2.
First, DWR servlet (UK. Ltd. getahead. DWR. dwrservlet) dojo and Ajax theme are required. DWR is used for normal verification of dojo to process Ajax results.
Next, configure DWR, write DWR. XML, and store it in the WEB-INF. The content is as follows:
<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN"
"http://www.getahead.ltd.uk/dwr/dwr10.dtd">
<dwr>
<allow>
<create creator="new" javascript="validator">
<param name="class" value="org.apache.struts2.validators.DWRValidator"/>
</create>
<convert converter="bean" match="com.opensymphony.xwork2.ValidationAwareSupport"/>
</allow>
<signatures>
<![CDATA[
import java.util.Map;
import org.apache.struts2.validators.DWRValidator;
DWRValidator.doPost(String, String, Map<String, String>);
]]>
</signatures>
</dwr>
Then you need to configure it to a web program and add the following configuration code to Web. xml: <servlet>
<Servlet-Name> DWR </servlet-Name>
<Servlet-class> UK. Ltd. getahead. DWR. dwrservlet </servlet-class>
<Init-param>
<Param-Name> debug </param-Name>
<Param-value> true </param-value>
</Init-param>
</Servlet>
<Servlet-mapping>
<Servlet-Name> DWR </servlet-Name>
<URL-pattern>/DWR/* </url-pattern>
</Servlet-mapping>
Finally, modify the JSP file edit. jsp in my struts2 Form Verification Article.
Add Ajax theme to the head, and add validate = "true" theme = "ajax" to the form. Now you can run it to experience the Ajax effect.