zoukankan      html  css  js  c++  java
  • jsp中jquery用法一步刷新 验证用户名是否存在

    <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

  • 相关阅读:
    [HEOI2014]人人尽说江南好 博弈论
    [HNOI2014]江南乐 博弈论
    [SDOI2011]黑白棋 kth
    [NOI2011]兔兔与蛋蛋游戏 二分图博弈
    [JSOI2009]游戏 二分图博弈
    口胡:[HNOI2011]数学作业
    【POJ】【2068】Art Gallery
    【CTSC 2015】&【APIO 2015】酱油记
    【BZOJ】【4052】【CERC2013】Magical GCD
    【BZOJ】【2750】【HAOI2012】Road
  • 原文地址:https://www.cnblogs.com/binggu/p/4071091.html
Copyright © 2011-2022 走看看