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

推荐订阅源

博客园_首页
The GitHub Blog
The GitHub Blog
美团技术团队
Know Your Adversary
Know Your Adversary
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The Register - Security
The Register - Security
Stack Overflow Blog
Stack Overflow Blog
Attack and Defense Labs
Attack and Defense Labs
G
Google Developers Blog
I
InfoQ
博客园 - 司徒正美
T
Troy Hunt's Blog
Google DeepMind News
Google DeepMind News
J
Java Code Geeks
MongoDB | Blog
MongoDB | Blog
博客园 - 聂微东
A
About on SuperTechFans
云风的 BLOG
云风的 BLOG
S
Security Affairs
M
MIT News - Artificial intelligence
Simon Willison's Weblog
Simon Willison's Weblog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
Tailwind CSS Blog
量子位
Vercel News
Vercel News
月光博客
月光博客
V
Vulnerabilities – Threatpost
N
News and Events Feed by Topic
Hugging Face - Blog
Hugging Face - Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
L
LangChain Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
L
LINUX DO - 最新话题
F
Full Disclosure
The Hacker News
The Hacker News
Hacker News: Ask HN
Hacker News: Ask HN
T
Tor Project blog
A
Arctic Wolf
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Forbes - Security
Forbes - Security
IT之家
IT之家
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Y
Y Combinator Blog
GbyAI
GbyAI
B
Blog RSS Feed
V
Visual Studio Blog
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs

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