接上一篇。在上一篇文章中介绍了利用ajax技术,从页面向后台传递数据,并判断数据库中是否有用户名重复的问题。如果存在重复的用户名,那么需要向js的ajax进行反馈。
我们之前建立的项目中,struts的jar包是不包含ajax的技术的,所以为了能够实现这个功能,需要添加新的jar包。即:
commons-lang3-3.8.1.jar
json-lib-2.2.3-jdk15.jar
struts2-json-plugin-2.1.8.jar
xwork-core-2.1.6.jar
这里需要注意的是,如果jar包的版本不同,可能会出现某些错误。
我们将这四个jar包下载下来,并复制到项目的lib目录下。跟我前面所讲的一样,选中jar包,右键,add as Library,OK。
然后File——Project Structure,Artifacts ,put into output root ——OK,如图:
接下来修改RegisterAction中的代码:
package com.kay.struts2.Action;
import com.opensymphony.xwork2.ActionSupport;
import com.yiibai.output.OutputHelper;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class RegisterAction extends ActionSuppor