0

htmlフォームを使用してjspを作成しました。これは、送信されるとサーブレットに送信されます。

私のフォームには、値が入力された複数の選択リストがあります。

私のサーブレットでは、値にいくつかの変更を加えたいと思います。

サーブレットのパラメータ値にアクセスしようとすると、すべてnullとして表示されます。

サーブレットからのスニペット:

String[] withAccess = req.getParameterValues("withAccess");

        for(int i = 0; i < withAccess.length; i++ )
            System.out.println(withAccess[i]);

このコードは「null」をN回出力します。ここで、Nは配列サイズです。

では、何が問題なのでしょうか。

私はそれを理解することはできません。

[送信]をクリックする前に、すべての要素が選択されています。

フォームが存在する私のhtmlファイル:

<html>
<script type="text/javascript" language="javascript" src="scripts.js"></script>

 <jsp:useBean id="bean2" class="models.JDBCModelAccess" scope="page"/>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
 <title>Insert title here</title>
 </head>
 <body>

 <form action="ModelConfiguration.do" method="post">

<label for="models">Models:</label>
<select name="models" id="models" onChange="makeRequest()">
<c:forEach var="model" items="${bean2.models}">
        <option>${model}</option>
    </c:forEach>
</select>

<label for="withoutAccess">Users without access to the model:</label>
<select name="withoutAccess" id="withoutAccess"size="5" multiple="multiple">      </select>

<label for="withAccess">Users with access to the model</label>
<select name="withAccess" id="withAccess" size="5" multiple="multiple"></select>

<input type="submit" value="Submit" onClick="selectAll(withoutAccess,withAccess,true)">

</form>
</body>
</html>
4

1 に答える 1

0

<option>タグ内に sがありません<select "withAccess" ...>

を持っているため、5 つの「アイテム」を取得していますがsize="5"、それらはすべて空です。

これを試して:

<select name="withAccess" id="withAccess" size="5" multiple="multiple">
    <option>User 1</option>
    <option>User 2</option>
    <option>User 3</option>
    <option>User 4</option>
    <option>User 5</option>
</select>
于 2012-07-04T13:37:02.423 に答える