Jsp 提交表单时为空值

Jsp 提交表单时为空值,jsp,Jsp,我的JSP页面中有一个三个单选按钮。我根据选择的单选按钮显示多选框。 但在提交表单时,我从两个选择框中得到空值。其他选择框工作正常 有人能帮我吗 <script type="text/javascript"> $(document).ready(function(){ $('.show').hide(); $("input[name$='application']").click(function() { var test = $(this).val(); $("div.show")

我的JSP页面中有一个三个单选按钮。我根据选择的单选按钮显示多选框。 但在提交表单时,我从两个选择框中得到空值。其他选择框工作正常

有人能帮我吗

<script type="text/javascript">
$(document).ready(function(){
$('.show').hide();
$("input[name$='application']").click(function() {
var test = $(this).val();
$("div.show").hide();
$('#showemma').hide();
$('#showdmfota').hide();
$('#showuep').hide();
$("#show" + test).show();
   });
});
</script>
<title>Add Config Changes</title>
</head>
<body>
<%
    Server env = new Server();
    Map<String, List<String>> map = env.getServer();
    Properties property = new Properties();
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    property.load(classLoader.getResourceAsStream("error.properties"));
%>
<h3> Add Configuration Change</h3> <br><br>
<form action="_config" method="post">
<table align="center" id ="login">
    <tr>
        <td>Application</td>
            <td>
            <div class="radio" style="font-size:12px;">
                <label><input type="radio" name="application" id="fota" value="dmfota"> DMFOTA</label>
                <label><input type="radio" name="application" id="uep" value="uep"> UEP</label>
                <label><input type="radio" name="application" id="emma" value="emma"> EMMA</label>
                </div>
            </td>
        <td id="error"><p id ="applicationError"><%=property.getProperty("applicationError") %></p></td>
    </tr>           

    <% for (String serverNamekey : map.keySet()){%>
    <tr id="show<%= serverNamekey %>" class="show" style='display:none'>

        <td>Server</td>
            <td>
            <% List<String> servers = map.get(serverNamekey); %>
                <select name="server" id="server" multiple="multiple" style="width:150px; height: 150px;">
                    <%for (String serverName : servers){  %>
                        <option value="<%=serverName%>"><%=serverName%></option>
                    <%} %>
                </select> 
            </td> 
            <td id="error"><p id ="serverError"><%=property.getProperty("serverError") %></p></td>
    </tr>
            <%} %>
    <tr>
        <td colspan =2><input type="submit" value="Add Change Log"   id="configSubmit" class="submit"></td>
    </tr>
</table>
</form> 
</body>
</html>

</table>
</form> 
</body>

如注释中所述,您的name属性在所有输入上都必须是唯一的,否则,服务器将只考虑一个值。此外,id也必须是唯一的

我建议使用serverNameKey作为唯一的名称和id:

请注意,您需要为所有input type=radio使用相同的name属性,这样该部分就可以了


与问题无关,我也建议不要使用scriplets,您应该阅读关于JSTL的内容。如果是一个新项目,我建议使用JSF,它接管了不推荐使用的JSP。

对于所有输入,您的输入名称始终为name=server,因此对于您的id,您应该为两者提供唯一性。@AlexandreLavoie:我已将id和名称更改为unqiue。它不起作用。你能更新你问题中的代码以查看更改吗?我已经更新了代码。请注意这个可恶的脚本,它在过去十年中一直受到高度劝阻。我会考虑你的建议。谢谢!!
<select id="select-<%= serverNamekey %>" name="<%= serverNamekey %>" ...