Please Enable JavaScript!
Mohon Aktifkan Javascript![ Enable JavaScript ]

JSP 실습 4(form 태그 )

2010. 4. 9. 14:03programming/jsp

728x90
 


4. input_id.jsp에서 ID와 패스워드, 성별을 입력 받고, 입력 받은 결과를 input_id_rst.jsp에서 출력하는 프로그램을 작성하시오.

<%-- input_id.jsp --%>
<%@page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!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=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<Form Action = "input_id_rst.jsp" Method = "post">

아이디   : <Input Type = "test"  Name = "id"> <BR>
<hr align=left width=300>
비밀번호 : <Input Type = "password" Name = "pass"> <BR>
<hr align=left width=300>
성 별 :남<input type=radio name=gender checked value="남">
     여<input type=radio name=gender value="여" >
<Br>
<hr align=left width=300>
<Input Type = "Submit" Value = "로그인">
<Input Type = "Reset" Value = "취소">
<hr align=left width=300>
</Form>
</body>
</html>

<%-- input_id_rst.jsp --%>

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!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=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<% request.setCharacterEncoding("euc-kr"); %>
<%

String id = request.getParameter("id");
String pass = request.getParameter ("pass");
String gender = request.getParameter("gender");
if ("a".equals(id)){
    if("a".equals(pass)){
%>
     
<%
    } else {
        out.println("<script> alert('비밀번호를 확인하세요');history.go(-1);</script>");
    }
} else {
    out.println("<script> alert('아이디를 확인하세요');history.go(-1);</script>");
}  
%>


<table border=1>
 <tr>
  <td>아이디</td>
  <td><%=id %></td>
 </tr>
 <tr>
  <td>비밀번호</td>
  <td><%=pass %></td>
 </tr>
 <tr>
  <td>성별</td>
  <td><%=gender%></td>
 </tr>
  
</table>

 

</body>
</html>

728x90