【发布时间】:2017-06-08 21:01:30
【问题描述】:
我正在尝试制作一个看起来像这样的表单。每行有两个下拉菜单:第一个是仅选择一个,另一个是选择多个。 Here is the output screen.
在此屏幕上,我想使用单个提交按钮将所有行的值(包括下拉菜单)发送到 servlet (Testing.java)。在Testing.java中,我基本上希望能够访问每个Test名称对应的每一行的所有值。
这是我在 imageimage 中显示的输出的 JSP 代码:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" import = "java.util.*" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="jquery chosen utils/chosen.css">
<link rel="stylesheet" type="text/css" href="jquery chosen utils/welcomestyle.css">
</head>
<body>
<div align = center>
<table style="width: 100%">
<tr>
<th> Script Name </th>
<th> Main Action Keywords </th>
<th> Sub Action Keywords </th>
</tr>
</table>
<%
for(int i =0; i<5;i++)
{
%>
<form action = "Testing">
<table style="width: 100%">
<tr>
<td> Test <%= i %> </td>
<td>
<div>
<select name = "Actions" class = "Actions" >
<%
for(int j=0;j<4;j++)
{
%>
<option value="Action<%= j %>">
Action <%= j %>
</option>
<%
}
%>
</select>
</div>
</td>
<td>
<select name = "SubActions" class = "SubActions" multiple>
<%
for(int k=0;k<4;k++)
{
%>
<option value="SubAction<%= k %>">
Sub Action <%= k %>
</option>
<%
}
%>
</select>
</td>
</tr>
</table>
<%
}
%>
<br><br>
<input type = submit value = "Submit" name ="submit" />
</form>
</div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script src="jquery chosen utils/chosen.jquery.js" type="text/javascript"></script>
<script src="jquery chosen utils/prism.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".Actions").chosen({
width: "75%"
});
$(".SubActions").chosen({
width: "75%"
});
});
</script>
</html>
我希望我的 Testing.java 是这样的:
import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/Testing")
public class Testing extends HttpServlet
{
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
String a = request.getParameter("Actions"); //Should get actions corrsponding to each test
String b = request.getParameter("SubActions"); //Should get subactions corrsponding to each test
}
}
Current Testing.java 只返回第一行(Test 0)的动作和第一个子动作。 我主要使用带有一点 jQuery 的 HTML 作为下拉菜单。
谁能给我建议如何做同样的事情?
【问题讨论】:
-
我建议为您的页面使用 Bootstrap 库,以使其更加简单和干净,并且您可以在表单中使用以下下拉菜单:link
标签: java forms jsp submit dropdown