用ssh2和jquery实现ajax交互,出现了点问题,求助,在线等待。。。。
具体如下:
前台:
<script type="text/javascript" src="js/jquery-1.3.1.js"></script>
<script type="text/javascript" src="js/register.js"></script>
</head>
<body>
<input type="text" name="register.email" id="email"/>
<span id="email-hint" class=""> </span>
</body>
js代码:
$(function(){
$("#email").focus(function(){
$('#email-hint').html("<span class='formtips onWaiting'></span>");
});
$("#email").blur(function(){
$.getJSON("reg.action",
"register.email=" + $("#email").val(),
function(data){
if (data.flag) {
$('#email-hint').html("<span class='formtips onSuccess'>" + data.responseText+ "</span>");
}else{
$('#email-hint').html("<span class='formtips onError'>" + data.responseText + "</span>");
}
});
})
})
java Action代码:
public class RegisterAction extends ActionSupport implements ModelDriven<Register>{
private Register register=new Register();
private RegisterService registerService;
private String responseText; //返回的结果
private boolean flag; //主要是为了效果好看点
public Register getRegister() {
return register;
}
public void setRegister(Register register) {
this.register = register;
}
public RegisterService getRegisterService() {
return registerService;
}
public void setRegisterService(RegisterService registerService) {
this.registerService = registerService;
}
public String getResponseText() {
return responseText;
}
public void setResponseText(String responseText) {
this.responseText = responseText;
}
public boolean isFlag() {
return flag;
}
public void setFlag(boolean flag) {
this.flag = flag;
}
public String emailExists() {
System.out.println("注册邮箱 :"+this.register.getEmail());
if (registerService.emailExists(this.register.getEmail())) {
flag = false;
responseText = "该用户名已经存在";
System.out.println("该用户名已经存在");
} else {
flag = true;
responseText = "可以注册";
System.out.println("可以注册");
}
return "success";
}
public Register getModel() {
// TODO Auto-generated method stub
return register;
}
}
重点struts.xml配置文件:
<package name="/" extends="json-default">
<action name="reg" class="registerAction" method="emailExists">
<result name="success" type="json">
<param name="includeProperties">${responseText},${flag}</param>
</result>
</action>
</package>
说明:执行完RegisterAction,然后报错:
java.lang.NoSuchMethodError: com.opensymphony.xwork2.ActionContext.get(Ljava/lang/Object;)Ljava/lang/Object;
at com.googlecode.jsonplugin.JSONResult.execute(JSONResult.java:153)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:373)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:277)
我想可能是下面的result配置错了,求大侠指点,在线等待,先谢谢了
<result name="success" type="json">
<param name="includeProperties">${responseText},${flag}</param>