struts2 json 传输数据

本文介绍了一种使用JavaScript进行客户端中文姓名验证的方法,并通过Ajax调用后端接口检查邮箱是否已被注册,确保用户输入的有效性和唯一性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

$(document).ready(function(){

  $("#a").blur(function(){ 

    var str =  $("#a").val(); // 得到焦点内容

// var str=document.getElementById("a").value; 

var reg = /^[/u4e00-/u9fa5]+$/i; //验证只能输入汉字的正则表达式

if (!reg.test(str)) 

{

alert("请输入中文名字!"); 

document.form1.a.focus(); 

//str.focus();

return false; 

}

   return true;

   });

});

 

 .action 中所写的

/**

* 检测邮箱是否存在

* @return

* @throws Exception

*/

public String emailCheck() throws Exception {

String email = (String) this.baseServiceIbatis.findObject("euser.eemailCheck", euser.getEmail());

if(email==null){

euser.setEmail("");

list = new ArrayList();

list.add(euser);

this.outJson(list, JsonType.Array);

return SUCCESS;

}

.jsp 页面所写的

//email账号

$("#adminusername").blur(function(){

var email = $(this).val();

if(email==""){

$("#tip_adminusername").html("").html("<font color='red'>请输入EMAIL地址!</font>");

return;

}

if(!testEmail(email)){

$("#tip_adminusername").html("").html("<font color='red'>EMAIL地址格式不正确!</font>");

return;

}

$.getJSON("enterprise/users/emailCheck.action", {"user.email":email}, function(json){

email = json[0].email;

 if(email==""){

  $("#tip_adminusername").html("").html("<font color='green'>恭喜你,你的邮箱可以注册!</font>");

  emailIsPass = true;

 }else{

  $("#tip_adminusername").html("").html("<font color='red'>该邮箱已注册!</font>");

  emailIsPass = false;

 }

 });

});

//用户名

$("#admintruename").blur(function(){

if($(this).val()==""){

$("#tip_admintruename").html("").html("<font color='red'>管理员名称不能为空!</font>");

return false;

}

});

 

if(emailIsPass=false){

$("#tip_adminusername").html("").html("<font color='red'>该邮箱已经注册!</font>");

}

 

struts.xml 中配置

<action name="emailCheck" class="euserAction" method="emailCheck">

<!-- <result type="json" />-->

</action>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值