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

推荐订阅源

Security Archives - TechRepublic
Security Archives - TechRepublic
博客园 - 三生石上(FineUI控件)
云风的 BLOG
云风的 BLOG
C
Check Point Blog
Engineering at Meta
Engineering at Meta
Y
Y Combinator Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Forbes - Security
Forbes - Security
IT之家
IT之家
L
LINUX DO - 最新话题
N
News and Events Feed by Topic
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
雷峰网
雷峰网
N
News | PayPal Newsroom
The Last Watchdog
The Last Watchdog
V
Visual Studio Blog
月光博客
月光博客
Microsoft Azure Blog
Microsoft Azure Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Webroot Blog
Webroot Blog
TaoSecurity Blog
TaoSecurity Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Schneier on Security
Schneier on Security
P
Privacy International News Feed
G
Google Developers Blog
博客园 - 聂微东
博客园 - 叶小钗
M
MIT News - Artificial intelligence
Apple Machine Learning Research
Apple Machine Learning Research
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
WordPress大学
WordPress大学
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Simon Willison's Weblog
Simon Willison's Weblog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
宝玉的分享
宝玉的分享
H
Hacker News: Front Page
Martin Fowler
Martin Fowler
L
Lohrmann on Cybersecurity
G
GRAHAM CLULEY
酷 壳 – CoolShell
酷 壳 – CoolShell
罗磊的独立博客
T
The Exploit Database - CXSecurity.com
S
Security @ Cisco Blogs
博客园_首页
AWS News Blog
AWS News Blog
P
Proofpoint News Feed
人人都是产品经理
人人都是产品经理
Help Net Security
Help Net Security
Google DeepMind News
Google DeepMind News
T
Threatpost

博客园 - 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返回