스프링 (26)

반응형

 

유효성 검사(validation)

 

: 입력한 데이터 값이 특정 규칙에 맞게 입력되었는지 검증하는 것

유효하지 않은 데이터 값을 입력할 시 부적합하다고 판명 -> 다시 폼 페이지로 되돌림

ex) 나이 입력, 회원 가입 시 아이디 중복 검사, 아이디 비밀번호 검사, IP 패킷 검사

 

=> 핸들러 함수 사용

 

 

 

  • 핸들러 함수

: 폼 페이지에서 이벤트 발생(submit 클릭)시 유효성 검사를 위해 매핑하는 메소드

자바 스크립트를 이용하여 코드를 작성

 

 

 

유효성 검사 예시

 

 

  • 아이디, 비밀번호 값 확인
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Validation</title>
<script type="text/javascript">
	function checkform() {
		let id = document.loginForm.id.value;
		let passwd = document.loginForm.passwd.value;
		
		console.log("id : " + id + ", passwd : " + passwd);
	}
</script>
</head>
<body>
	<!-- 폼페이지 
	action 생략 : action="validation01.jsp" method="get"
	-->
	<form name="loginForm">
		<p>아이디 : <input type="text" name="id" /></p>
		<p>비밀번호 : <input type="password" name="passwd" /></p>
		<!-- checkform() : 핸들러 함수 -->
		<p><input type="button" value="전송" onclick="checkform()" /></p>
	</form>
</body>
</html>

 

결과 화면1

 

 

 

  • 유효성 검사 체크
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Validation</title>
<script type="text/javascript">
	function checkLogin() {
		let form = document.loginForm;
		let id = form.id.value;
		let passwd = form.passwd.value;
		
		console.log("id : " + id + ", passwd : " + passwd);
		if(id=="") {
			alert("아이디를 입력해주세요.");
			form.id.focus(); //해당 입력 항목에 커서를 위치
			return;
		} else if(passwd == "") {
			alert("비밀번호를 입력해주세요.");
			form.passwd.focus();
			return;
		}
		//위의 분기문을 잘 통과
		form.submit();
	}
</script>
</head>
<body>
	<!-- 폼페이지 
	action 생략 : action="validation01.jsp" method="get"
	-->
	<form name="loginForm">
		<p>아이디 : <input type="text" name="id" /></p>
		<p>비밀번호 : <input type="password" name="passwd" /></p>
		<!-- checkLogin() : 핸들러 함수 -->
		<p><input type="button" value="전송" onclick="checkLogin()" /></p>
	</form>
</body>
</html>

 

결과 화면2

 

 

 

  • 아이디, 비밀번호 글자 수 제한

validation04.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>validation</title>
<script type="text/javascript">
	function checkLogin(){
		let form = document.loginForm;
		// 아이디 : 4~12자 이내로 입력
		if(form.id.value.length < 4 || form.id.value.length > 12) {
			alert("아이디는 4~12자 이내로 입력 가능합니다.");
			form.id.select();
			return;
		}
		// 비밀번호 : 4자 이상으로 입력
		if(form.passwd.value.length < 4) {
			alert("비밀번호는 4자 이상으로 입력해야 합니다.");
			form.passwd.select(); // focus() : 커서를 위치
			return;
		}
		
		// 모두 통과했다면
		form.submit();
	}
</script>
</head>
<body>
	<!-- 폼페이지 
	요청 URI : validation04_process.jsp
	요청 파라미터 : {id=a001&passwd=java}
	요청방식 : post
	-->
	<form name="loginForm" action="validation04_process.jsp" method="post">
		<p>아이디 : <input type="text" name="id" /></p>
		<p>비밀번호 : <input type="password" name="passwd" /></p>
		<!-- checkLogin() : 핸들러 함수 -->
		<p><input type="button" value="전송" onclick="checkLogin()" /></p>
	</form>
</body>
</html>

 

 

validation04_process.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
	<h3>입력에 성공했습니다.</h3>
	<!-- 폼페이지 
	요청 URI : validation04_process.jsp
	요청 파라미터 : {id=a001&passwd=java}
	요청방식 : post
	-->
	<%
		// 문자 인코딩 유형 처리
		request.setCharacterEncoding("UTF-8");
		String id = request.getParameter("id"); //a001
		String passwd = request.getParameter("passwd"); //java
	%>
	<p>아이디 : <%=id%></p>
	<p>비밀번호 : <%=passwd%></p>
</body>
</html>

 

결과 화면3-1 : 아이디 확인

 

결과 화면3-2 : 비밀번호 확인

 

결과 화면3-3 : 입력 성공 화면

 

 

 

  • 이름 유효성 추가

validation05.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>validation</title>
<script type="text/javascript">
	function checkLogin(){
		let form = document.loginForm;
		// 아이디 : 4~12자 이내로 입력
		if(form.id.value.length < 4 || form.id.value.length > 12) {
			alert("아이디는 4~12자 이내로 입력 가능합니다.");
			form.id.select();
			return;
		}
		// 비밀번호 : 4자 이상으로 입력
		if(form.passwd.value.length < 4) {
			alert("비밀번호는 4자 이상으로 입력해야 합니다.");
			form.passwd.select(); // focus() : 커서를 위치
			return;
		}
		
		// "1admin".substr(0,1) => 1
		// It is Not a Number : 그것은 숫자가 아니다.
		// isNaN
		if(!isNaN(form.name.value.substr(0,1))){ // 1
			// 숫자라면
			alert("이름은 숫자로 시작할 수 없습니다.");
			form.name.focus();
			return;
		}
		
		// 모두 통과했다면
		form.submit();
	}
</script>
</head>
<body>
	<!-- 폼페이지 
	요청 URI : validation04_process.jsp
	요청 파라미터 : {id=a001&passwd=java}
	요청방식 : post
	-->
	<form name="loginForm" action="validation04_process.jsp" method="post">
		<p>아이디 : <input type="text" name="id" /></p>
		<p>비밀번호 : <input type="password" name="passwd" /></p>
		<p>이름 : <input type="text" name="name" /></p>
		
		<!-- checkLogin() : 핸들러 함수 -->
		<p><input type="button" value="전송" onclick="checkLogin()" /></p>
	</form>
</body>
</html>

 

결과 화면4

 

 

 

  • 아이디 영문 소문자만 가능, 비밀번호는 숫자만 입력 가능
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>validation</title>
<script type="text/javascript">
	function checkLogin(){
		let form = document.loginForm;
		// 아이디 : 4~12자 이내로 입력
		if(form.id.value.length < 4 || form.id.value.length > 12) {
			alert("아이디는 4~12자 이내로 입력 가능합니다.");
			form.id.select();
			return;
		}
		
		// A001 = > 아이디는 영문 소문자만 가능
		for(let i=0;i<form.id.value.length; i++) {
			let ch = form.id.value.charAt(i);
			
			if( (ch<'a' || ch>'z')&&(ch>='A' || ch<='Z')&&(ch>='0' || ch<='9') ) {
				alert("아이디는 영문 소문자만 입력 가능합니다.");
				form.id.select();
				return;
			}
		}
		
		// 비밀번호 : 4자 이상으로 입력
		if(form.passwd.value.length < 4) {
			alert("비밀번호는 4자 이상으로 입력해야 합니다.");
			form.passwd.select(); // focus() : 커서를 위치
			return;
		}
		
		// 비밀번호는 숫자만 입력 가능. isNaN
		if( isNaN(form.passwd.value) ) {
			alert("비밀번호는 숫자만 입력 가능합니다.");
			form.passwd.select();
			return;
		}
		
		
		
		// "1admin".substr(0,1) => 1
		// It is Not a Number : 그것은 숫자가 아니다.
		// isNaN
		if(!isNaN(form.name.value.substr(0,1))){ // 1
			// 숫자라면
			alert("이름은 숫자로 시작할 수 없습니다.");
			form.name.focus();
			return;
		}
		
		// 모두 통과했다면
		form.submit();
	}
</script>
</head>
<body>
	<!-- 폼페이지 
	요청 URI : validation04_process.jsp
	요청 파라미터 : {id=a001&passwd=java}
	요청방식 : post
	-->
	<form name="loginForm" action="validation04_process.jsp" method="post">
		<p>아이디 : <input type="text" name="id" /></p>
		<p>비밀번호 : <input type="password" name="passwd" /></p>
		<p>이름 : <input type="text" name="name" /></p>
		
		<!-- checkLogin() : 핸들러 함수 -->
		<p><input type="button" value="전송" onclick="checkLogin()" /></p>
	</form>
</body>
</html>

 

결과 화면5-1

 

결과 화면5-2

 

 

반응형

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

[스프링] 15장 쇼핑몰 시스템4  (0) 2024.04.12
[스프링] 14장 정규 표현식  (0) 2024.04.12
[스프링] 11장 파일 업로드  (0) 2024.04.09
[스프링] 10.5장 과제  (0) 2024.04.08
[스프링] 10장 쇼핑몰 시스템2  (0) 2024.04.02
반응형

 

파일 업로드(file upload)

 

: 웹 브라우저에서 서버로 파일을 전송하여 서버에 저장하는 것

텍스트 파일, 바이너리 파일, 이미지 파일, 문서 등 여러가지 파일을 업로드 할 수 있음.

JSP의 폼 태그를 사용하며 파일을 서버에 저장하기 위해 오픈 라이브러리를 이용함.

 

 

 

  • JSP 페이지 폼태그 작성 규칙
<form action="JSP 파일" method="post" enctype="multipart/form-data">
	<input type="file" name="요청 파라미터 이름" multiple>
</form>

 

1. form 태그

2. method 속성은 post

3. enctype 속성은 multipart/form-data

4. action 속성은 JSP 파일

5. input 태그의 type 속성은 file

 

 

 

+ 라이브러리 파일

 

 

 

Commons-FileUpload

 

: 파일 업로드 패키지

서버의 메모리상에서 파일 처리가 가능하도록 지원함.

commons-fileupload.jar, commons-io.jar 파일을 배포 사이트에서 다운로드해서 사용.

 

 

 

  • DiskFileUpload 클래스의 메소드
메소드 유형 설명
setRepositoryPath(String repositoryPath) void 파일을 입시 저장할 디렉터리 설정
setSizeMax(long sizeMax) void 최대 파일 크기 설정
setSizeThreshold(int sizeThreshold) void 메모리상 저장할 최대 크기 설정
parseRequest(HttpServletRequest req) void multipart/form-data 유형의 요청 파라미터 가져옴

 

 

 

 

  • 파일 업로드

fileupload04.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>File Upload</title>
</head>
<body>
	<!-- 파일 업로드 시 체킹!
		1) form태그
		2) method="post"
		3) enctype="multipart/form-data"
		4) action="업로드를처리할 jsp의 url주소"
		5) <input type="file".. (multiple) />
	 -->
	 <!-- 
		요청URI : fileupload04_process.jsp
		요청파라미터 : {filename=파일객체}
		요청방식 : post
     -->
	 <form action="fileupload04_process.jsp" method="post" enctype="multipart/form-data">
	 	<p>파일 : <input type="file" name="filename" /> </p>
	 	<p><input type="submit" value="파일올리기" /></p>
	 </form>
</body>
</html>

 

 

fileupload04_process.jsp

<%@page import="java.io.File"%>
<%@page import="org.apache.commons.fileupload.FileItem"%>
<%@page import="java.util.Iterator"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ page import="org.apache.commons.fileupload.DiskFileUpload"%>
<%@ page import="java.util.List"%>
<!-- 
	요청URI : fileupload04_process.jsp
	요청파라미터 : {filename=파일객체}
	요청방식 : post
-->
<%
	// 업로드할 윈도우 경로 : 역슬러시 두 개
	String path = "C:\\upload"; // 위치에 폴더를 미리 생성해놔야 함
	
	// commons-fileupload.jar 안에 해당 클래스가 있음
	DiskFileUpload upload = new DiskFileUpload();
	
	// 업로드할 파일의 최대 크기
	upload.setSizeMax(5000000); // 5Mbyte
	// 메모리에 저장할 최대 크기
	upload.setSizeThreshold(5 * 4095); // 5 * 1024 * 1024 : 5Mbyte
	
	// 업로드된 파일을 입시로 저장할 경로
	upload.setRepositoryPath(path);
	
	
	// 요청파라미터 : {filename=파일객체}
	// parse : 구문분석 / 의미분석
	List items = upload.parseRequest(request);
	
	// 요청 파라미터를 Iterator(열거형) 클래스로 변환
	Iterator params = items.iterator();
	// 요청 파라미터가 없어질때까지 반복(1회 반복 예정)
	while(params.hasNext()) {
		// FileItem : 1) 일반 폼데이터 2) 파일
		FileItem item = (FileItem)params.next();
		
		if(item.isFormField()) { // 1) 일반(input type="text", radio, checkbox, textarea, select)
			

		} else { // 파일(input type="file" name="filename")(o)
			// 요청파라미터 : {filename=파일객체} => item
			String fileFieldName = item.getFieldName(); // filename 
			String fileName = item.getName(); // 업로드된 파일의 이름 (ex : chi12.png)
			String contentType = item.getContentType(); // 만약 이미지파일이라면 MIME TYPE : image/png
			long fileSize = item.getSize(); // 파일 크기
			
			//fileName => C:\\Users\\PC10\\Pictures\\chi12.png
			//파일명만 추출(경로는 제외)
			//마지막 \\의 위치를 찾아서 +1을 하면 1이 나오는데 거기서부터 끝까지 추출 => chi12.png
			fileName = fileName.substring(fileName.lastIndexOf("\\")+1);
	        
			// 계획. c:\\upload\\chi12.png
			File file = new File(path + "\\" + fileName);
			// 복사 실행
			// 파일객체.write(계획)
			item.write(file);
	        
			out.print("===============================<br />");
			out.print("요청 파라미터 이름 : " + fileFieldName + "<br />");
			out.print("저장 파일 이름 : " + fileName + "<br />");
			out.print("파일 콘텐츠 유형 : " + contentType + "<br />");
			out.print("파일 크기 : " + fileSize + "<br />");
		}
	}
%>

 

 

 

결과 화면1

 

결과 화면2

 

 

 

  • 파일 중복 방지 업로드

fileupload05.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
	// 이미지 미리보기 시작
	// <input type="file" id="filename" name="filename" />
	// $("input[name='filename']")
	$("#filename").on("change", handleImg);
	
	function handleImg(e){
		//e.target : <input type="file" id="uploadFile" name="filename" />
		let files = e.target.files; // 파일들
		// fileArr = [a.jpg, b.jpg, c.jpg]
		let fileArr = Array.prototype.slice.call(files);
		$("#pImg").html("");
		
		// f : 파일오브젝트 1개
		fileArr.forEach(function(f){
			// 이미지 체킹
			if(!f.type.match("image.*")) {
				alert("이미지 확장자만 가능합니다.");
				return; // 함수 종료
			}

			// 이미지가 맞으면
			let reader = new FileReader();
			// e : reader가 이미지 객체를 읽는 이벤트
			reader.onload = function(e) {
				let img_html = "<img src='" + e.target.result + "' style='width:10%;' />";
				$("#pImg").append(img_html);
			}
			reader.readAsDataURL(f);
		});
	}
});
</script>
<title>File Upload</title>
</head>
<body>
	<!-- 파일 업로드 시 체킹!
		1) form태그
		2) method="post"
		3) enctype="multipart/form-data"
		4) action="업로드를처리할 jsp의 url주소"
		5) <input type="file".. (multiple) />
	 -->
	 <!-- 
		요청URI : fileupload05_process.jsp
		요청파라미터 : {name=개똥이, subject=개똥이의 모험, filename=파일객체}
		요청방식 : post
     -->
	 <form id="fileForm" name="fileForm" action="fileupload05_process.jsp" method="post" 
	 		enctype="multipart/form-data">
	 	<!-- FileItem, isFormField() : true -->
	 	<p>이름 : <input type="text" name="name" /></p>
	 	<p>제목 : <input type="text" name="subject" /></p>
	 	<p id="pImg"></p>
	 	
	 	<!-- FileItem, isFormField() : false -->
	 	<p>파일 : <input type="file" id="filename" name="filename" multiple/></p>
	 	<p><input type="submit" value="파일올리기" /></p>
	 </form>
</body>
</html>

 

 

fileupload05_process.jsp

<%@page import="java.io.File"%>
<%@page import="java.util.UUID"%>
<%@page import="org.apache.commons.fileupload.FileItem"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ page import="org.apache.commons.fileupload.DiskFileUpload"%>
<!-- 
	요청URI : fileupload05_process.jsp
	요청파라미터 : {name=개똥이, subject=개똥이의 모험, filename=파일객체}
	요청방식 : post
-->
<%
	String path = "c:\\upload";
	DiskFileUpload upload = new DiskFileUpload();
	upload.setSizeMax(5000000); // 5M
	upload.setSizeThreshold(5*4096);
	upload.setRepositoryPath(path); // 임시저장경로
	
	List items = upload.parseRequest(request);
	Iterator params = items.iterator(); // 요청 파라미터들을 담음
	while(params.hasNext()) {
		FileItem item = (FileItem)params.next();
		
		if(item.isFormField()) { // 1) name=개똥이, subject=개똥이의 모험
			String name = item.getFieldName(); // name, subject
			String value = item.getString("UTF-8"); // 개똥이, 개똥이의 모험
			out.print(name + "=" + value + "<br />");
		} else { // 2) filename=파일객체
			String fileFieldName = item.getFieldName(); // filename
			String fileName = item.getName(); // c:\\users\\picture\\사진
			String contentType = item.getContentType(); // MIME
			long fileSize = item.getSize();
			fileName = fileName.substring(fileName.lastIndexOf("\\")+1);
			
			
			// 파일 중복 방지 시작
			// java.util.UUID => 랜덤값 생성
			UUID uuid = UUID.randomUUID();
			//sdalfksadjk_111가1236.jpg
			fileName = uuid.toString() + "_" + fileName;
			// 파일 중복 방지 끝
			
			
			File file = new File(path + "\\" + fileName);
			// 복사 실행
			item.write(file);
			
			out.print("===============================<br />");
	        out.print("요청 파라미터 이름 : " + fileFieldName + "<br />");
	        out.print("저장 파일 이름 : " + fileName + "<br />");
	        out.print("파일 콘텐츠 유형 : " + contentType + "<br />");
	        out.print("파일 크기 : " + fileSize + "<br />");
		}
	}
	
%>

 

결과 화면3

 

결과 화면4

 

 

반응형

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

[스프링] 14장 정규 표현식  (0) 2024.04.12
[스프링] 13장 유효성 검사  (0) 2024.04.11
[스프링] 10.5장 과제  (0) 2024.04.08
[스프링] 10장 쇼핑몰 시스템2  (0) 2024.04.02
[스프링] 8.5장 과제  (0) 2024.04.01
반응형

 

연습 문제 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
1 2 3 4 5 6 7 8 9