从java servlet获取div值中的复选框

时间:2018-05-29 12:45:38

标签: java jsp servlets checkbox

我无法获得" no_del_file"的复选框值。进入servlet。

这是我的JSP:

 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 
 <html>
 <head>
  <title>List of Command menu</title>


 </head>
 <body>
<div><b>${reply}</b></div>
<div id="wrapper">
<div id="menu">
<form action="runButtonCommand" method="post" name="myform"> 
<a href="runButtonCommand?param1=list apps" >List1</a><br/><br/>
<a href="runButtonCommand?param1=list data" >List2</a><br/><br/>
<br/><br/>

no del: 

<%String test = (String)request.getParameter("no_del_file"); %>
<%String checked = "";%>

<% 
if ("on".equals(test)) {
    checked="checked=\"on\"";

} %>
<input type="checkbox" name="no_del_file" <%=checked%>>
<br />

</form>

</div>
<div id="output">
  <p>Output:</p>
  <textarea style="resize: none;" data-role="none" rows="40" cols="120" name="outputarea">
  ${data}
  </textarea>
  </div>

</div>
</body>
</html>

这是Servlet部分,我尝试获取复选框值:

 protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    String[] tester= request.getParameterValues("no_del_file");
    System.out.println("Start: "+tester);
    performTask(request, response);
}

然而,如果我使用getParameterValues,getParameter或getAttribute并不重要,如果选中或取消选中,我总是变为null。我怎样才能获得这个价值?

感谢您的帮助。

海盗

0 个答案:

没有答案