如何将listbox的值从jsp传递给servlet? [英] how to Pass the value of listbox from jsp to servlet?

查看:195
本文介绍了如何将listbox的值从jsp传递给servlet?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的javascript是

my javascript is

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即可。

You don't need JS for this. Just HTML is enough.

<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() 获取所选值:

And then in the servlet use HttpServletRequest#getParameterValues() to obtain the selected values:

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

这篇关于如何将listbox的值从jsp传递给servlet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆