JSP 내장객체란?
자주 사용되는 객체(클래스 9개)로 별도의 선언 없이 사용 가능하다
대표적으로 request, response, session 등이 있다.
이번 예는 request 를 중심으로 만든 회원가입 페이지이다.
Result
RequestJoin.jsp
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR" %> <!DOCTYPE html> <html> <head> <meta charset="EUC-KR" > <title>Insert title here</title> </head> <body> <center> <h2>Join</h2> <form action="RequestJoinProc.jsp" method="post" > <table width="500" border="1" > <tr height="50" > <td width="150" align="center">ID</td> <td width="350" align="center" > <input type="text" name="id" size="40" placeholder="Write the ID" /> </td> </tr> <tr height="50" > <td width="150" align="center">Password</td> <td width="350" align="center" > <input type="password" name="pass1" size="40" /> </td> </tr> <tr height="50" > <td width="150" align="center">Password check</td> <td width="350" align="center" > <input type="password" name="pass2" size="40" /> </td> </tr> <tr height="50" > <td width="150" align="center">E-mail</td> <td width="350" align="center" > <input type="email" name="email" size="40" /> </td> </tr> <tr height="50" > <td width="150" align="center">Phone Number</td> <td width="350" align="center" > <input type="tel" name="tel" size="40" /> </td> </tr> <tr height="50" > <td width="150" align="center">Hobby</td> <td width="350" align="center" > <input type="checkbox" name="hobby" value="exercise" >Exercise <input type="checkbox" name="hobby" value="programming" >Programming <input type="checkbox" name="hobby" value="reading" >Reading </td> </tr> <tr height="50" > <td width="150" align="center">Job</td> <td width="350" align="center" > <select name="job" > <option>Teacher</option> <option>Programmer</option> <option>Doctor</option> <option>Student</option> <option>Unemployed</option> </select> </td> </tr> <tr height="50" > <td width="150" align="center">Age</td> <td width="350" align="center" > <input type="radio" name="age" value="20" >20 s <input type="radio" name="age" value="30" >30 s <input type="radio" name="age" value="40" >40 s <input type="radio" name="age" value="50" >50 s </td> </tr> <tr height="50" > <td width="150" align="center">Your Story</td> <td width="350" align="center" > <textarea rows="5" cols="40" name="info"></textarea> </td> </tr> <tr height="50" > <td align="center" colspan="2" > <input type="submit" value="Join Now" > <input type="reset" value="Cancel" > </td> </table> </form> </center> </body> </html>
RequestJoinProc.jsp
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR" %> <!DOCTYPE html> <html> <body> <center> <h2>Member information</h2> <% request.setCharacterEncoding("EUC-KR" ); String id = request.getParameter("id" ); String pass1 = request.getParameter("pass1" ); String pass2 = request.getParameter("pass2" ); String email = request.getParameter("email" ); String tel = request.getParameter("tel" ); String[] hobbies = request.getParameterValues("hobby" ); String job = request.getParameter("job" ); String age = request.getParameter("age" ); String info = request.getParameter("info" ); if (!pass1.equals(pass2)){ %> <script type="text/javascript" > alert("The password is not corret." ); history.go(-1 ); </script> <% } %> <center> <table width="500" border="1" > <tr height="50" > <td width="150" align="center">ID</td> <td width="350" align="center" > <%= id %> </tr> <tr height="50" > <td width="150" align="center">Password</td> <td width="350" align="center" > <%= pass1 %> </tr> <tr height="50" > <td width="150" align="center">E-mail</td> <td width="350" align="center" > <%= email %> </tr> <tr height="50" > <td width="150" align="center">Phone Number</td> <td width="350" align="center" > <%= tel %> </tr> <tr height="50" > <td width="150" align="center">Hobby</td> <td width="350" align="center" > <% for (int i=0 ; i < hobbies.length; i++){ out.write(hobbies[i]+ " " ); } %> </td> </tr> <tr height="50" > <td width="150" align="center">Job</td> <td width="350" align="center" > <%= job %> </tr> <tr height="50" > <td width="150" align="center">Age</td> <td width="350" align="center" > <%= age %> </tr> <tr height="50" > <td width="150" align="center">Your Story</td> <td width="350" align="center" > <%= info %> </tr> </table> </center> </center> </body> </html>
Table of Contents JSP 내장객체란?