반응형

 

연습 문제 01

 

 

form 태그에 사용하는 속성에 대해 간단히 설명하시오.

 

더보기

action 속성

: 폼 데이터를 받아 처리하는 웹 페이지 URL 설정

 

method 속성

: 폼 데이터가 전송되는 HTTP 방식 설정

 

name 속성

: 폼 식별을 위한 name 설정

 

target 속성

: 폼 처리 결과의 응답을 실행할 프레임 설정

 

enctype 속성

: 폼을 전송하는 콘텐츠 MIME 유형을 설정

 

accept-charset 속성

: 폼 전송에 사용할 문자 인코딩 설정

 

 

 

연습 문제 02

 

 

form 태그 내에 중첩하여 사용하는 태그를 나열하고 설명하시오.

 

더보기

1. input 태그

: 텍스트 입력이나 비밀번호 입력 등 다양하게 기입할 수 있도록 공간을 만드는 태그

 

2. select 태그

: 여러 항복이 나타나는 목록 상자에서 항목을 선택하는 태그

 

3. textarea 태그

: 여러 줄의 텍스트를 입력할 수 있는 태그

 

 

 

연습 문제 03

 

 

폼 페이지에서 전송된 데이터를 전달받는 내장 객체와 관련된 메소드는 무엇인가?

 

더보기

내장 객체 : request

 

메소드 : getParameter()

 

 

 

연습 문제 04

 

 

form 태그를 이용하여 다음 조건에 맞게 JSP 애플리케이션을 만들고 실행 결과를 확인하시오.

 

 

더보기

form01.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
	<form action="form01_process.jsp" method="post">
		이름 : <input type="text" name="name"><br>
		주소 : <input type="text" name="addr"><br>
		이메일 : <input type="text" name="email"><br>
		<input type="submit" value="전송">
	</form>
</body>
</html>

 

 

form01_process.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<%
	request.setCharacterEncoding("UTF-8");

	String name = (String)request.getParameter("name");
	String addr = (String)request.getParameter("addr");
	String email = (String)request.getParameter("email");
	
	StringBuffer sb = new StringBuffer();
	sb.append("아이디 : " + name + "<br>");
	sb.append("주소 : " + addr + "<br>");
	sb.append("이메일 : " + email + "<br>");
	
	out.print(sb.toString());
%>
</body>
</html>

  

결과 화면1

 

결과 화면2

 

 

 

 

연습 문제 05

 

 

form 태그를 이용하여 다음 조건에 맞게 JSP 애플리케이션을 만들고 실행 결과를 확인하시오.

 

 

더보기

form02.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
	<form action="form02_process.jsp" method="post">
		이름 : <input type="text" name="name"><br>
		주소 : <input type="text" name="addr"><br>
		이메일 : <input type="text" name="email"><br>
		<input type="submit" value="전송">
	</form>
</body>
</html>

 

 

form02_process.jsp

<%@page import="java.util.Enumeration"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<%
	request.setCharacterEncoding("UTF-8");
	
	Enumeration en = request.getParameterNames();
	StringBuffer sb = new StringBuffer();
	while(en.hasMoreElements()) {
		String name = (String)en.nextElement();
		String value = request.getParameter(name);

		sb.append(name + " : " + value + "<br />");
	}
	out.print(sb.toString());
%>
</body>
</html>

 

 

결과 화면3

  

결과 화면4

 

 

 

연습 문제 06

 

 

form 태그를 이용하여 다음 조건에 맞게 JSP 애플리케이션을 만들고 실행 결과를 확인하시오.

 

 

더보기

form03.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Implict Objects</title>
</head>
<body>
<form action="form03_process.jsp" method="post">
	오렌지<input type="checkbox" name="friut" value="Orange">
	사과<input type="checkbox" name="friut" value="Banana">
	바나나<input type="checkbox" name="friut" value="Apple">
	<input type="submit" value="전송">
</form>
</body>
</html>

 

 

form03_process.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h2>선택한 과일</h2>
<%
	String friut[] = request.getParameterValues("friut");
	for(int i=0; i<friut.length; i++) {
		out.print(friut[i] + " ");
	}
%>

</body>
</html>

  

결과 화면5

 

결과 화면6

 

 

 

 

 

 

 

 

 

 

반응형

'스프링' 카테고리의 다른 글

[스프링] 13장 유효성 검사  (0) 2024.04.11
[스프링] 11장 파일 업로드  (0) 2024.04.09
[스프링] 10장 쇼핑몰 시스템2  (0) 2024.04.02
[스프링] 8.5장 과제  (0) 2024.04.01
[스프링] 8장 response 객체  (0) 2024.04.01