반응형

HTML

<form id="form" method="post">
    <input type="text" id="no" name="no"/>
    <input type="text" id="date" name="date"/>
    <input type="hidden" id="arrayParam" name="arrayParam"/>
    <c:forEach var="item" items="${codeList}">
         <input type="checkbox" name="chk_code" value="${item.code}"> 
         ${item.codename}
    </c:forEach>
</form>
																

 

JQuery

var array = new Array(); // 배열 선언
$('input:checkbox[name=chk_code]:checked').each(function() { // 체크된 체크박스의 value 값을 가지고 온다.
    array.push(this.value);
});
			
$("#arrayParam").val(array);
	
$("#form").attr("action", "/test/test.do");  
$("#form").submit();

 

JAVA (Spring 프레임워크 기반)

@RequestMapping(value = "/test/test.do")
    public String test(@RequestParam HashMap<String, Object> commandMap) throws Exception {
        String[] code_array = null;
		 
        String code = commandMap.get("arrayParam").toString();
        code_array = code.split(",");		
		
        int[] results= new int[code_array.length];
        int result=1;
		
        for(int i=0; i < code_array.length; i++){
            HashMap<String, Object> resendMap = new HashMap<String, Object>();
	        
            resendMap.put("code", code_array[i]);
            resendMap.put("no", commandMap.get("no"));
            resendMap.put("date", commandMap.get("date"));
	        
            results[i] = testDAO.addTestCode(resendMap);
            
            result *= results[i];
        }
        
        return test/result;
    }
반응형

+ Recent posts