我在用jquery validation做一个简单的登陆验证,其中用户名要在失去焦点之后验证是否存在,我就用到了remote,但是程序老是报错如下:
警告: Could not find action or resultNo result defined for action web.LoginForm and result success at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:375)
前台jsp页面代码如下:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/javascript" src="js/jquery-1.5.1.min.js"></script> <script type="text/javascript" src="js/jquery.validate.js"></script> <script type="text/javascript" src="js/jquery.form.js"></script> <link rel="stylesheet" href="css/screen.css" type="text/css"></link> <script> $(document).ready(function() { var jsonn ="${json}"; if (null!=jsonn && jsonn.length!=0){ alert(jsonn); } $("#loginForm").validate( { rules : { name : { required : true, minlength : 2, remote: { url: "validateData.action", //后台处理程序 type: "post", //数据发送方式 dataType: "json", //接受数据格式 data: { //要传递的数据 username: function () { return $("#name").val(); } } }, password : { required : true, minlength : 4 } } }, messages : { name : { remote:"用户名不存在", required : "*用户名不能为空", minlength : "*用户名至少是两位" }, password : { required : "*密码不能为空", minlength : "*密码长度至少是4位" } } }); });</script> <title>登陆页面</title> </head> <body> <div style="position: absolute; left: 50%; top: 50%;"> <form action="loginForm" method="post" id="loginForm"> <p> <label style="height: 100px" for="name"> 用户名: </label> <input type="text" id="name" name="name" style="width: 150px"> </p> <p> <label style="height: 100px" for="password"> 密 码: </label> <input type="password" id="password" name="password" style="width: 150px"> </p> <p> <input type="submit" value="登陆" id="submit"> <input type="reset" value="重置" id="reset"> </p> </div> </form> </body></html>后台java代码如下:
public String validateData(){ HttpServletRequest request = ServletActionContext. getRequest(); String username =request.getParameter("username"); System.out.println(username); if("haha".equals(username)){ this.result=false; } else{ this.result=true; } return SUCCESS; }struts配置如下:
<package name="web" extends="json-default"> <action name="validateData" class="web.LoginForm" method="validateData"> <result name="success" type="json"> <param name="defaultEncoding">UTF-8</param> <param name="root">result</param> </result> <result name="error" type="json"> <param name="defaultEncoding">UTF-8</param> </result> </action> </package> 请各位大牛哥帮助。
添加回答
举报
0/150
提交
取消