JEE 양식 기반 인증의 샘플 로그인 및 오류 페이지

JEE 양식 기반 인증에서 사용자 정의된 로그인 페이지 및 오류 페이지를 지정할 수 있습니다. 사용자 ID 및 비밀번호를 입력하도록 사용자에게 프롬프트가 표시되는 로그인 페이지는 특수 j_security_check 서블릿을 참조합니다. 두 개의 HTTP 요청 매개변수(입력 필드 형성)는 항상 요청에 있어야 합니다(하나는 호출된 j_username 및 다른 하나는 j_password).

웹 컨테이너가 j_security_check 서블릿에 대한 요청을 수신할 때, 이는 인증을 수행하기 위해 요청을 애플리케이션 서버의 보안 메커니즘으로 전달합니다. 인증에 실패하면 오류 페이지가 표시됩니다. 아래는 샘플 로그인 페이지의 코드입니다. WebContent 폴더 아래의 login.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>Sample Login Page for JEE Security</title>
<style type="text/css">H1 {color: navy}</style>
</head>
<body>
<table width="500" border="0">
   <tbody>
      <tr>
         <td colspan="3" width="80%" align="center"><b><font face="Verdana"size="+2" 
             color="#15406a">Sample Login</font></b><hr>
         </td>
      </tr>
      <tr>
         <td colspan="3" width="560" height="65">
         <form method="POST" action="j_security_check">
         <div>
         <table width="100%" border="1" bgcolor="#e9e9e9">
            <tbody>
               <tr>
                  <td align="right" width="169" 
                      bgcolor="#e9e9e9"><b>
                      <font face="Verdana">User id:</font></b></td>
                  <td width="315"><input type="text" name="j_username"></td>
               </tr>
               <tr>
                  <td align="right" width="169" bgcolor="#e9e9e9">
                      <font face="Verdana"><b>Password:</b></font></td>
                  <td width="315"><input type="password" name="j_password"></td>
               </tr>
               <tr bgcolor="white">
                  <td align="right" width="169" bgcolor="white"></td>
                  <td width="315"><input type="submit" value="Login"></td>
               </tr>
            </tbody>
         </table>
         </div>
         </form></td>
      </tr>
      <tr>
         <td colspan="3" width="560" align="center" height="58" valign="top">
            <script> document.write(Date()+".")
            </script>
         </td>
      </tr>
   </tbody>
</table></body>
</html>

다음은 샘플 오류 페이지의 코드입니다. WebContent 폴더 아래의 error.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>Sample Error Page for JEE Security</title>
<style type="text/css">H1 {color: navy}</style>
</head>
<body>
<table width="500" border="0">
   <tbody>
      <tr>
         <td colspan="3" width="80%" align="center"><b><font face="Verdana" size="+2" 
             color="#15406a">Sample Login Error</font></b><hr>
         </td>
      </tr>
      <tr>
         <td colspan="3" width="560" align="center" height="58" 
             valign="top"><br>Authentication error. 
             Please check your user id and password, and try again.</td>
      </tr>
   </tbody>
</table></body>
</html>