通过jsp struts中的post发送选择多个值

时间:2015-05-23 19:02:33

标签: jsp struts struts-1

我在jsp中构建一个网页,您可以在其中添加,查看和删除作者,书籍和社论。 在addBook jsp中,它需要选择书的编辑和编写它的作者。 问题出在struts动作中,我试图捕捉通过post发送的值。

<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

   <script>
    $(document).on("ready",function(){
        $("#bAdd").on("click", function(){
            var option=$("#authorsSelect option:selected").text();
            $("#saveAuthors").append('<option>'+option+'</option>');
            $("#authorsSelect option:selected").remove();
        });
        $("#bDel").on("click", function(){
            var option=$("#saveAuthors option:selected").text();
            $("#authorsSelect").append('<option>'+option+'</option>');
            $("#saveAuthors option:selected").remove();
        });
    });
   </script>
    <title>JSP Page</title>
</head>
<body>
    <h1><bean:message key="book.ins"/></h1>
    <form method="post" action="./insertBook.do?method=myAction1">
        title: <input type="text" id="title" name="title" required/> <br/>
        Year: <input type="number" id="yer" name="yer" required /><br/>
        Editorial: 
        <select  name="editorial">
            <logic:iterate name="editorialsList" id="editorial" scope="request">
                <option value="<bean:write name="editorial" property="id" />">
                    <bean:write name="editorial" property="name"/>
                </option>
            </logic:iterate>
        </select><br/>
        price: <input type="number" id="price" name="price" required /><br/>
        Select one or more authors:<br/>
        <select multiple id="authorsSelect" class="comboMultiple">
            <logic:iterate name="authorsList" id="autor" scope="request">
                <option value="<bean:write name="autor" property="id" />">
                    <bean:write name="autor" property="name"/> <bean:write name="autor" property="lName"/>
                </option>
            </logic:iterate>
        </select>
        <section id="botons" class="botons">
            <input type="button" id="bAdd" value=">>">
            <input type="button" id="bDel" value="<<">
        </section>
        <select multiple="multiple"  name="authorsSelect">
            <option> </option>
        </select>
        <input type="submit" value="insert">
    </form>
</body>
</html>  

这是我检索信息的地方     公共类InsertBookAction扩展DispatchAction {

public ActionForward myAction1(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    String title = (String)request.getParameter("title");
    int year = Integer.parseInt(request.getParameter("year"));
    String editorial = (String)request.getParameter("editorial");
    int price = Integer.parseInt(request.getParameter("price"));
    String[] authors = request.getParameterValues("authorsSelect");
    for(int i=0;i<autores.length;i++){
        JOptionPane.showMessageDialog(null,authors[i]);
    }
    return mapping.findForward(SUCCESS);
}
}

在线       String [] authors = request.getParameterValues(&#34; authorsSelect&#34;); 我得到一个空值,有人可以给我一个提示我做错了吗

0 个答案:

没有答案