2012-07-04 46 views
0

我已经创建了一个带有html表单的jsp,它在提交时转到servlet。选择列表值传递为空

在我的表单中,我有一个多选列表,填充了值。

在我的servlet中,我想让值做一些修改。

当我尝试访问servlet中的参数值时,它们都显示为空。

片段从servlet的:

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

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

此代码输出 “无效” 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> 
+1

您不必在这些列表框的任何选项都没有。我想你会以某种方式使用JavaScript填充它们,并在那里做错了。您应该调试您的JS代码并重新构建您的问题。这与JSP/Servlet完全无关。 – BalusC

+0

对不起,我不确定错误在哪里。我正在使用我的selectAll()函数,并且我没有放置options.value = ...,所以只出现了文本,但是这些值没有传递给servlet。谢谢 – Wasted

+0

我不知道'selectAll()'函数的作用。这不是标准的JS API的一部分,因此是一个本土功能。没有看到你的JS代码就无法回答这个问题。 – BalusC

回答

0

你没有<option>是你<select "withAccess" ...>标签内。

由于您有size="5",因此您将获得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> 
+0

未选定的选项根本不通过。 – BalusC