繁体   English   中英

如何将列表框的值从jsp传递到servlet?

[英]how to Pass the value of listbox from jsp to servlet?

我的JavaScript是

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;
    }

您不需要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");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM