2014-01-16 2 views
1

동적 프로젝트에 로그인 페이지 (HTML)를 만들었습니다. 나는 사용자 이름과 비밀 번호가 잘못된 경우 mysql 데이터베이스와 사용자 이름과 비밀 번호를 확인하고 같은 페이지에 오류 메시지를 표시하고 싶습니다. 오류 페이지 대신 오류 메시지를 표시하고 싶기 때문에 여기에 서블릿을 사용하여 오류 페이지를 표시하고 싶지 않습니다. 어떻게 이것을 동적 웹 프로젝트에서 수행 할 수 있습니까? 자바 스크립트, jQuery, JSP 또는 이들의 조합을 사용할 수 있습니까?사용자 이름과 암호를 확인하여 오류 메시지를 표시하는 방법은 무엇입니까?

+1

사용할 수는 그 모든. 어떤 서버 측 언어를 사용할 수 있습니까? – MonkeyZeus

+0

자바 스크립트 유효성 검사 엔진이 더 좋습니다. http://www.position-relative.net/creation/formValidator/ –

+1

AJAX가 무엇을 찾고 있습니다. JQuery가 바로 그것을 지원합니다 – Reeno

답변

0

나는 JSP에 익숙하지 오전하지만 여기 당신이 필요로하는 작업에 대한 개요입니다 :

index.html을

<!DOCTYPE HTML> 
<html> 
    <head> 
     <title>Web Form</title> 
     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 
     <script> 
      $(document).ready(function() { 

       $('form').on('submit', function(e) { 
        // don't let the browser submit the form 
        e.preventDefault(); 

        // send form data to JSP page 
        $.ajax({ 
         url: 'process.jsp', 
         async: true, 
         cache: false, 
         type: 'POST', 
         data: $(this).serialize(), 
         dataType: 'html', 
         success: function(data) { 
          // place message in error box 
          $('#error_box').html(data); 

          // if "Success" then redirect if you would like 
          if(data === 'Success!'){ 
           // window.location = 'some other page/website'; 
          } 
         } 
        }); 
       }); 

      }); 
     </script> 
    </head> 

    <body> 
     <form method="POST" action="process.jsp"> 
      <input type="text" name="username" /> 
      <input type="password" name="password" /> 
      <input type="submit" value="submit" /> 
     </form> 
     <div id="error_box"></div> 
    </body> 
</html> 

process.jsp

// I don't know JSP 
// use the POST values and check your DB 
// Upon success/failure just echo the message 
// <%='Success!'%> 
// <%='Failed!'%> 
+0

당신이 내 대답을 받아 들였을 때, 코드가 효과가 있었습니까? – MonkeyZeus

관련 문제