惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Project Zero
Project Zero
Security Archives - TechRepublic
Security Archives - TechRepublic
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Security @ Cisco Blogs
AI
AI
博客园_首页
The Last Watchdog
The Last Watchdog
S
SegmentFault 最新的问题
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Know Your Adversary
Know Your Adversary
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Google Online Security Blog
Google Online Security Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Security Affairs
Blog — PlanetScale
Blog — PlanetScale
V2EX - 技术
V2EX - 技术
www.infosecurity-magazine.com
www.infosecurity-magazine.com
云风的 BLOG
云风的 BLOG
The GitHub Blog
The GitHub Blog
O
OpenAI News
Scott Helme
Scott Helme
C
Cisco Blogs
雷峰网
雷峰网
H
Help Net Security
P
Palo Alto Networks Blog
MyScale Blog
MyScale Blog
I
Intezer
Security Latest
Security Latest
N
News | PayPal Newsroom
美团技术团队
N
News and Events Feed by Topic
B
Blog RSS Feed
T
Tor Project blog
小众软件
小众软件
T
Tenable Blog
aimingoo的专栏
aimingoo的专栏
U
Unit 42
MongoDB | Blog
MongoDB | Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Application and Cybersecurity Blog
Application and Cybersecurity Blog
月光博客
月光博客
L
Lohrmann on Cybersecurity
T
Tailwind CSS Blog
K
Kaspersky official blog
C
Cyber Attacks, Cyber Crime and Cyber Security
WordPress大学
WordPress大学
P
Proofpoint News Feed
有赞技术团队
有赞技术团队
Apple Machine Learning Research
Apple Machine Learning Research
P
Privacy International News Feed

博客园 - lodestar

一张图掌握数据存储 使用xtrabackup实现mysql定时热备份 开发篇1:使用原生api和Langchain调用大模型 预热篇2:从RNN到Transformmer 预热篇1:大模型训练显卡选型 macbook安装scala、hadoop、saprk环境 centos6.5 squid安装 一次linux服务器黑客入侵后处理 linux上搭建svn服务器 Windows系统下Oracle每天自动备份 android中listView的几点总结 使用template method模式简化android列表页面 andorid进度条使用 andorid定时器应用 - lodestar Android网络应用(第一部分) - lodestar 错误数据导致java.lang.IllegalArgumentException:Unsupported configuration attributes 使用ACEGI搭建权限系统:第三部分 acegi安全框架使用:第二部分 使用ACEGI实现权限控制,第一部分
ajax实现用户名存在校验
lodestar · 2011-11-29 · via 博客园 - lodestar

ajax方式实现:用户名在数据库中的存在校验,网上非常多了
1、可以用javaScript调用action
if(window.ActiveXObject)
  {
   xmlHttpd = new ActiveXObject("Microsoft.XMLHTTP");    
  }
   else if(window.XMLHttpRequest)
  {
   xmlHttpd = new XMLHttpRequest();
  }
  
uri = encodeURI(uri + "?" + key:value); 

xmlHttpd.open("post",uri,false);
    
xmlHttpd.onreadystatechange = function()
  {
   if(xmlHttpd.readyState==4){
    if(xmlHttpd.status==200){
     //ajax调用成功后的操作
     var rt = xmlHttpd.responseText.replace(/\s/ig,'');
     ***********
     }
    }
  }
  
xmlHttpd.send(null);
 }
注意事项:
1、后台如果是strtus2的话,key要在action中注入,或者采用标准写法:实体类.属性。struts2会使用拦截器构造实体类,并注入action
2、如果action的编码是utf-8,页面编码是gbk,那么参数在action中是乱码,需进行编码转换
3、返回参数也是一样,如果页面和action的编码不一致的话,response要设置编码setCharacterEncoding("GBK"),否则回传中文会出现乱码

2.jquery实现
$(function() {
         $("#rolename").bind("blur", function(){
      var rolename=$.trim($("#rolename").val());
      if (rolename.length > 0)
      {
     $.get("validateRole.action",
        $("#newrole").serialize(), //序列化表单数据
        callback,"html");
      }
   })
        })
 //接收服务器返回的数值,将服务器返回的数据动态的显示在页面上
    function callback(data){
      var rt = data.replace(/\s/ig,'');
      if (rt == 2){
       $("#showResult").html("角色名已存在");
       $("#rolename").focus();
      } else if (rt == 3){
       $("#showResult").html("角色验证失败请联系管理员");
      } else if (rt == 1){
       $("#showResult").text("*格式:ROLE_");
      }
    }
   
 jquery的serialize会自动构造key:value参数,注意事项同js实现
   
2.服务器端使用HttpServletResponse.getWriter获得PrintWriter对象,回写返回信息
 也可以使用dwr调用,将整个action状态作为josn返回