티스토리 뷰

Send05.html

<%@ page contentType="text/html; charset=UTF-8"%>
<%
   String name=request.getParameter("name");
   String memo=request.getParameter("memo");
   String[] chk =request.getParameterValues("box");

   	out.println("이름:"+name);
   	out.println("메모내용:"+memo);
   	out.println("<br>");
   try{
      // 선택한 값이 없으면 back.
      if(chk == null || chk.length <= 0){
        return;
      }
      for(int i=0; i<chk.length; i++){
        out.println("선택한 값 : " + chk[i] + "<br>");
      }
      out.println(" ");
   }catch(Exception e){
      System.out.println(e);
   }
   %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	
   
</body>
</html>​

Receive05.jsp

<%@ page contentType="text/html; charset=UTF-8"%>
<%
   String name=request.getParameter("name");

	//메모수신
   String memo=request.getParameter("memo");
   memo=memo.replaceAll("\n","<br>"); 
   // replaceAll은 JDK1.5부터 사용 가능
   //ReplaceAll 함수는 자신이 바꾸고싶은 문자로 문자열을 전부 치환
	
   //★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
   //※같은 name 속성의 값을 가진 데이터 여러개를 받는(수신)경우
   // 이를 배열로 처리해야 한다.
   //또한 같은 name 속성의 값을 가진 데이터 여러개를 받는 경우
   //아래와 같이 배열로 처리해야 하며,
   //이렇게 처리할 경우(배열) 데이터가 전혀 없는 경우는 배열의 값이
   //null이되어 버리게 된다. 그렇기 때문에 null에 대한 검사가 반드시 필요하다.!!
   //★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
   String[] chk =request.getParameterValues("box");

   	out.println("이름:"+name);
   	out.println("메모내용:"+memo);
   	out.println("<br>");
   try{
      // 선택한 값이 없으면 back.
      if(chk == null || chk.length <= 0){
        return;
      }
      for(int i=0; i<chk.length; i++){
        out.println("선택한 값 : " + chk[i] + "<br>");
      }
      out.println(" ");
   }catch(Exception e){
      System.out.println(e);
   }
   %>
   
   
   <%-- 강사님 풀이
    String str="";
    
    if(chk !=null)
    {
    	for(String temp : chk)
    	{
    		str+="["+temp+"]";
    		}
   	}
    --%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	
   
</body>
</html>

※replaceA은 문자 로 문자열을 전부 치환한다 !!! 

※또한 배열로 name값들을 받을경우 null값을 꼭 체크하자 !!!