2016-03-17 1 views
0

Когда chcek имеет имя пользователя, он всегда дает mesg «Имя пользователя недоступно». Как решить эту проблему. пожалуйста, помогите мне Заранее спасибо за Yous предложение или решениеИсправление удаленной загрузки Bootstrap не работает должным образом с java

Регистрация страницы

**Reg.jsp** 

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
     pageEncoding="ISO-8859-1"%> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
    <html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
    <title> ON-DB &nbsp; &nbsp; &nbsp;Registration</title> 
    <link rel="shortcut icon" href="images/online-chart-sold-products-by-region.png"> 
    <link rel="stylesheet" href="css/bootstrap.css"/> 
     <link rel="stylesheet" href="css/bootstrapValidator.css"/> 

     <script type="text/javascript" src="js/jquery-1.11.3.min.js"></script> 
     <script type="text/javascript" src="js/bootstrap.min.js"></script> 
     <script type="text/javascript" src="js/bootstrapValidator.js"></script> 
    </head> 
    <body> 

    <div class="main"> 
    <%@include file="Header.jsp" %> 
    <div class="container"> 

     <div class="row"> 
      <section> 
      <div class="col-lg-8 col-lg-offset-2"> 

       <div class="page-header"> 
        <h2>Registration</h2> 
       </div> 

       <form action="RegistrationSevlet" id="defaultForm" method="post" class="form-horizontal" > 
        <div class="form-group" id="CheckUsername"> 
         <label class="col-lg-3 control-label">Username</label> 
         <div class="col-lg-5"> 
          <input type="text" class="form-control" name="username" /><span class="status"></span> 
         </div> 
         <div class="progress" id="progressBar" style="margin: 5px 0 0 0; display: none;"> 
          <div class="progress-bar progress-bar-success progress-bar-striped active" style="width: 100%"></div> 
         </div> 
        </div> 
        <div class="form-group"> 
         <label class="col-lg-3 control-label">First Name </label> 
         <div class="col-lg-5"> 
          <input type="text" class="form-control" name="firstName" /> 
         </div> 
        </div> 
        <div class="form-group"> 
         <label class="col-lg-3 control-label">Last Name </label> 
         <div class="col-lg-5"> 
          <input type="text" class="form-control" name="lastName" /> 
         </div> 
        </div> 

        <div class="form-group"> 
         <label class="col-lg-3 control-label">Email </label> 
         <div class="col-lg-5"> 
          <input type="text" class="form-control" name="email" /> 
         </div> 
        </div> 

        <div class="form-group"> 
         <label class="col-lg-3 control-label">Password</label> 
         <div class="col-lg-5"> 
          <input type="password" class="form-control" name="password" /> 
         </div> 
        </div> 

        <div class="form-group"> 
         <div class="col-lg-9 col-lg-offset-3"> 
          <input type="submit" class="btn btn-default" value="SignUp"/> 
         </div> 
        </div> 
       </form> 
      </div> 
      </section>s 
     </div> 
    </div> 
    </div> 
    <script type="text/javascript"> 
    $(document).ready(function() { 
     $('#defaultForm') 

      .bootstrapValidator({ 
       framework: 'bootstrap', 
       message: 'This value is not valid', 
       feedbackIcons: { 
        valid: 'glyphicon glyphicon-ok', 
        invalid: 'glyphicon glyphicon-remove', 
        validating: 'glyphicon glyphicon-refresh' 
       }, 
       fields: { 
        username: { 
         threshold: 6, 
         message: 'The username is not valid', 
         validators: { 

          notEmpty: { 
           message: 'The username is required and can\'t be empty', 
          }, 
          stringLength: { 
           min: 6, 
           max: 20, 
           message: 'The username must be more than 6 and less than 20 characters long', 
          }, 

          regexp: { 
           regexp: /^[a-zA-Z0-9_\.]+$/, 
           message: 'The username can only consist of alphabetical, number, dot and underscore', 
          }, 
           remote: { 
           type: "POST", 
           url: 'Check1', 
           delay:1000, 

           message: 'The username is not available', 

          }, 


         } 
        }, 
        firstName: { 
         validators: { 
          notEmpty: { 
           message: 'The first name is required and cannot be empty' 
          } 
         } 
        }, 
        lastName: { 
         validators: { 
          notEmpty: { 
           message: 'The last name is required and cannot be empty' 
          } 
         } 
        }, 

        email: { 
         validators: { 
          notEmpty: { 
           message: 'The email is required and can\'t be empty' 
          }, 
          emailAddress:{ 
           message: 'The input is not a valid ' 
          } 
         } 
        }, 
        password: { 
         validators: { 
          notEmpty: { 
           message: 'The password is required and can\'t be empty' 
          } 
         } 
        } 
       } 
      }) 

    }); 
    </script> 

    </body> 
    </html> 

Servlet

Check.java

открытый класс Check1 расширяет HttpServlet { частный статический окончательный длинный serialVersionUID = 1L;

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
{ 

    String user_db=null; 
     PrintWriter out = response.getWriter(); 

     String uname=request.getParameter("username"); 
     System.out.println(uname); 
     String SQL="SELECT username FROM userinfo WHERE username='"+uname+"'"; 
     Connection con=DBConnection.getConnection(user_db); 

     Statement st; 
     ResultSet rs; 

     boolean status=false; 

    try 
    { 
     st=con.createStatement(); 
     rs=st.executeQuery(SQL); 
     System.out.println(SQL); 

     if(!rs.next()) 
     { 
      status=false; 
     out.print(status); 
      System.out.println("false"); 
     } 
     else 
     { 
     status=true; 
     out.print(status); 

      System.out.println("true"); 
     } 
    } 
    catch(Exception ex) 
    { 
     ex.printStackTrace(); 
    } 

}}

ответ

0

данные отправку обратно в загрузочный валидатор не в правильном формате JSON. Измените его, чтобы исправить json-формат, и я буду работать.

Это сработало для меня. Измените его в соответствии с ур требованием

 public class RegistrationEmailCheck extends HttpServlet { 
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
    response.setContentType("application/json"); 

    PrintWriter out = response.getWriter(); 
JSONObject json = new JSONObject(); 
String availEmail = request.getParameter("email"); 
System.out.println(availEmail); 
String SQL = "SELECT email FROM login WHERE email='" + availEmail + "'"; 
Connection con = DBInfo.getConn(); 
Statement st; 
ResultSet rs; 

try { 
    st = con.createStatement(); 
    rs = st.executeQuery(SQL); 


    if (rs.next()) { 

     out.print("{\"valid\" : false }"); 
     json.put("valid", false); 
     System.out.println("false"); 


    } else { 

     out.print("{\"valid\" : true }"); 
     json.put("valid", true); 
     System.out.println("true"); 


    } 


} catch (Exception ex) { 
    ex.printStackTrace(); 
} finally { 

    out.close(); 
    } 



} 


} 
+0

несколько раз может получить проблему JSon так прописать путь => Щелкните правой кнопкой мыши на проекте в затмении -> Buildpath -> Настройка Построить путь -> Java Путь компоновки (левая панель) - > Библиотеки (вкладка) -> Добавить внешние банки -> Выберите свою банку и выберите ОК. А также добавьте в Assassment развертывания. Щелкните правой кнопкой мыши по проекту в eclipse -> Развертывание asssembly-> щелкните по add –

Смежные вопросы