<script type="text/javascript">     

/*   $(document).ready(function(){

      var id="ha";
var s="<td>用户名:<select name='"+id+"'>"+"<option>sdfsdf</option></select>" $("#f").html(s); })
*/ function func(){ document.form1.action="index.jsp?opt=0";
document.form1.submit(); } function funcs(){ if(!document.getElementById("name").value)
{ document.getElementById("name").value='请输入用户名';document.getElementById("name").style.color='#999'; }
else{
var name=document.getElementById("name").value;
$.ajax({
type: "POST",
url:"my.jsp",
data:"name="+name, success:function(name){
document.getElementById("tip").innerHTML=name; }
}); }
} function focus(){
alert("wocaonima"); // if(document.getElementById("user.name").value=='input') document.getElementById("user.name").value="";
if(document.getElementById("name").value=='input')
{ document.getElementById("name").value="";
alert("haobuhao1");
this.style.color='#000';
}
} </script> <!-- onfocus="if(value=='请输入用户名') {value='';this.style.color='#000';}" onblur="if(!value) {value='请输入用户名';this.style.color='#999';}" --> <% if(session.getAttribute("username")==null)
{ %>
<body>
<center>
<form method="post" name="form1">
<table>
<tr><div id="f"><td>用户名:<input type="text" id="name" name="name" onfocus="if(value=='请输入用户名') {value='';this.style.color='#000';}" onblur="funcs()"></td></div><td><label id="tip"></label></tr>
<tr><td>密码:<input type="password" name="password"></td></tr>
<tr><td> <input type="button" value="提交" onclick="func()" align="middle"> </td></tr> </table></form> </center>
</body> <%} else{ %> <script type="text/javascript"> window.location.href="index.jsp"; </script> <%
} %>

my.jsp为ajax的处理页面,代码如下

<%@page import="java.io.PrintWriter"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.gree.ConnDB" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <%
String name= request.getParameter("name");
String data="";
int result=0;
// response.setContentType("text/html");
PrintWriter outs=response.getWriter();
if(name==null) {
name="";
System.out.print("haha");
}
ConnDB db=new ConnDB();
result=db.test(name); if(result==0) data="<p style='color:red;'> 该用户名不存在!</p>";
else data="<p style='color:blue;'> 用户名输入正确</p>";
outs.write(data); %>

此处PrintWriter类的write方法可以将处理后的数据返还给login.jsp

jsp中jquery用法一步刷新 验证用户名是否存在的更多相关文章

  1. AJAX实现无刷新验证用户名

    register.php <html> <head> <meta http-equiv="content-type" content="te ...

  2. MVC4中 jquery validate 不用submit方式验证表单或单个元素

    正确引入MVC4 jquery验证的相关文件 <script src="/Scripts/jquery-1.4.4.js"></script> <sc ...

  3. MVC中 jquery validate 不用submit方式验证表单或单个元素

    <script src="/Scripts/jquery-1.4.4.js"></script> <script src="/Scripts ...

  4. 【转】 ASP.NET使用ICallbackEventHandler无刷新验证用户名是否可用

    功能说明:当用户在用户名输入框输入字符并焦点离开此输入框时,自动到数据库用户表中验证此用户名是否已被注册,如果已被注册,显示[不可用],反之,显示[可用],期间页面不刷新,读者也可以考虑将提示文字换成 ...

  5. Ajax实现注册无刷新验证用户名是否存在

    1. [代码][JavaScript]代码     ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 ...

  6. 利用jQuery实现的Ajax 验证用户名是否存在

    异步刷新实现方式有多种,也可以借助JS的多种框架,下面是使用jQuery框架实现的AJAX 验证用户名是否存在 jQuery.ajax概述 HTTP 请求加载远程数据. 通过jQuery 底层 AJA ...

  7. jsp中的jquery失效以及引入js失败的问题

    这段时间在试着看公司用的框架是怎么写的,看到项目中对jquery进一步封装的这一部分,所以自己试着写一些demo来模仿框架中的用法. 再一次的,又遇到了一个问题,jsp中引入js的问题,好久没有自己从 ...

  8. jsp中include的两种用法

    JSP中的include的两种用法 1.两种用法 <%@ include file=” ”%> <jsp:include page=” ” flush=”true”/> 2.用 ...

  9. JAVA基础之sql模糊匹配、外键以及jsp中include的用法

    一.SQL模糊匹配 适用于对字符串进行模糊搜索 格式:   字段名 Like '%关键词%'      %          表示这个位置可有任意个字符(没有也可以) %关键词%  只要包含关键词就算 ...

随机推荐

  1. eclipse快捷键补全

    Eclipse中 补全快捷键 默认Alt+/ 但是每个人习惯有所不同 我需要来修改自己熟悉的快捷键 windows->preferences->General->keys将Conte ...

  2. [canvas入坑3] 类似ps中魔术棒或者画图中油漆桶的功能

    查看效果请到 http://philippica.github.io/  点击fill 这功能其实实现很low,最早高一看黑书的时候看到了floodfill算法感觉好神奇,转念一想这不就是bfs么!! ...

  3. js setInterval 启用&停止

    以下面例子为说明: <title></title> <script src="Scripts/jquery-1.4.1-vsdoc.js" type= ...

  4. 设置Animation 的播放位置

    AnimationState.normalizedTime 官方文档的描述 Description The normalized time of the animation. A value of 1 ...

  5. WebService 序列化和反序列化

    参考了Fish LI的Xml读取文章,写了XML序列化和反序列化的文章. 序列化:把实体列转化成XML.反序列化:把XML按一定的规则转化成需要的实体列. 序列化和反序列化化使用到的类, using ...

  6. PE笔记之NT头PE签名

    typedef struct _IMAGE_NT_HEADERS {       DWORD Signature;                     //PE头签名PE\0\0       IM ...

  7. 一个简单的NoSQL内存数据库—Berkeley DB基本操作的例子

    一个简单的NoSQL内存数据库—Berkeley DB基本操作的例子 最近,由于云计算的发展,数据库技术也从结构式数据库发展到NoSQL数据库,存储模式从结构化的关系存储到现在如火如荼的key/val ...

  8. 《Linux命令行与shell脚本编程大全 第3版》Linux命令行---2

    以下为阅读<Linux命令行与shell脚本编程大全 第3版>的读书笔记,为了方便记录,特地与书的内容保持同步,特意做成一节一次随笔,特记录如下: <Linux命令行与shell脚本 ...

  9. 小谈c#数据库存取图片的方式

    第一种方式   文件夹与数据库配合 /// <summary> /// 上传图片 /// </summary> /// <param name="FUSShop ...

  10. 使用Powerdesigner生成设计的数据表(一张或多张)的测试数据

    设计表完成以后,我们需要生成一些测试数据,可以直接更新到数据库中,下面我们就来试试: 第一步:建立需要的Profiles测试文件,[Model]--[Test Data Profiles],如图所示: ...