2013-01-04 4 views
0

저는 전자 상담 프로젝트에서 일하고 있습니다. 한 번에 여러 지점과 학교를 선택하겠습니다. SelectedValues가 항상 null이라는 사실을 발견했습니다. 문제가 무엇인지 말해주십시오.jsp에서 servlet으로 선택한 체크 박스 값이 null입니다.

<table border="1" cellpadding="0" cellspacing="0" > 
     <% for(i=0;i<branchSchools.length;i++){ %> 
     <tr class=<%= (i%2==0)?"rowstyle":"altrowstyle" %> > 
      <td> 
      <input type="checkbox" name="SelectedBranchSchool" id='SelectedBranchSchool<%= i %>' value="<%= i %>"> 
      </td> 
      <td > 
       <%= branchSchools.item[i].branchCode %> 
      </td> 
      <td > 
       <%= branchSchools.item[i].school %> 
       </td> 
       <td align="right"> 
       <form name="frm5" action="addMultipleChoiceFill" method="post"> 
        <% request.getSession().setAttribute("BranchSchools",branchSchools); 
        request.getSession().setAttribute("FilledChoices",filledChoices); 
        %> 
       <input type="submit" name="addmult" value="AddMultiple"/> 
       </form> 
      </td> 
    ![enter image description here][1] 

protected void processRequest(HttpServletRequest request, HttpServletResponse response) 
throws ServletException, IOException { 
    BranchSchools branchSchools=null; 
    FilledChoices filledChoices=null; 
    branchSchools=(BranchSchools) request.getSession().getAttribute("BranchSchools"); 
    request.getSession().removeAttribute("BranchSchools"); 
    filledChoices=(FilledChoices)request.getSession().getAttribute("FilledChoices"); 
    request.getSession().removeAttribute("FilledChoices"); 
    String[] SelectedValues = request.getParameterValues("SelectedBranchSchool"); 
    for(int i=0; i<SelectedValues.length; i++){ 
     int k=Integer.valueOf(SelectedValues[i]); 
     filledChoices.addFilledChoice(branchSchools.item[k]); 
     branchSchools.removeBranchSchool(k); 
    } 
    request.setAttribute("BranchSchools",branchSchools); 
    request.setAttribute("FilledChoices",filledChoices); 
    request.setAttribute("Change", "yes"); 
    RequestDispatcher rd=getServletContext().getRequestDispatcher("/choiceFill.jsp?"); 
    rd.forward(request,response); 

답변

1

귀하의 체크 박스 형태에 있지, 그래서 폼이 제출 될 때 제출 아니에요 :

또한
<input type="checkbox" name="SelectedBranchSchool" ...> 
... 
<form name="frm5" action="addMultipleChoiceFill" method="post"> 
    ... 
    <input type="submit" name="addmult" value="AddMultiple"/> 
</form> 

는, 명명 규칙 자바를 존중하고, MVC는 JSTL에 대해 자세히 읽고 모범 사례.

관련 문제