<form action="GetList" method="post">
<input name="xx" type="checkbox" value="1"> 第一個<input name="x1" type="text"> <br>
<input name="xx" type="checkbox" value="2"> 第二個<input name="x2" type="text"><br>
<input name="xx" type="checkbox" value="3"> 第三個<input name="x3" type="text"><br>
<input name="xx" type="checkbox" value="4"> 第四個<input name="x4" type="text"><br>
<input name="submit1" type="submit" value="提交">
</form>
package com.jr.action;
import java.io.IOException;
import java.util.LinkedHashMap;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@SuppressWarnings("serial")
public class GetList extends HttpServlet {
public GetList() {
super();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
String[] s=request.getParameterValues("xx");
LinkedHashMap<String, String> map=new LinkedHashMap<String, String>();
for (int i = 0; i < s.length; i++) {
String string = s[i];
if (request.getParameter("x"+string)!=null&&!request.getParameter("x"+string).trim().equals("")) {
String value=request.getParameter("x"+string);
map.put(string, value);
}
}
}
public void init() throws ServletException {
}
}