2010-11-15 86 views
0

我的JavaScript如何將listbox的值從jsp傳遞給servlet?

function takeListBoxValue() 
    { 
     document.frmPartnerList.submit(); 
     var selectArray = new Array(); 
     for (i = 0; i < partnerList.length; i++) 
       { 
        selectArray[i] = new Array(); 
        selectArray[i][0] = partnerList.options[i].text; 
        selectArray[i][1] = partnerList.options[i].value; 
       } 
       document.frmPartnerList.<%=RateCardConstant.ACTION_MODE_PARAMETER%>.value='<%=(new Long(RateCardActionConstant.PARTNER_DOMAIN_LIST_ACTION).toString())%>&dataValue='+selectArray; 
    } 

回答

1

你不需要JS這一點。只需HTML就足夠了。

<form action="servleturl" method="post"> 
    <select name="listbox" multiple="true"> 
     <option value="value1">label1</option> 
     <option value="value2">label2</option> 
     <option value="value3">label3</option> 
    </select> 
    <input type="submit"> 
</form> 

然後在servlet使用HttpServletRequest#getParameterValues()以獲得選擇的值:

String[] listbox = request.getParameterValues("listbox"); 
+0

感謝溶液 – vanita 2010-11-17 10:22:58