日期:2014-05-18  浏览次数:20950 次

check 的request.getParameter
<input type="checkbox" id="needmemberpwd" name="needmemberpwd" value="0" onClick="checkmemberof(this)" class="checkstyle">


<input type="checkbox" id="needmemberpwd" name="needmemberpwd" value="1" onClick="checkmemberof(this)" class="checkstyle">

当用request.getparameter("needmemberpwd"),value是1时,得到的是1,是0时得到的不是0,确实null,这是怎么回事啊?

------解决方案--------------------
checkbox是0的时候是没有选中,没选中的不会提交,所以getPara得到null

就用 是否null 来判断有没有选中就好了
------解决方案--------------------
测试了一下没有你说的问题,如果只有一个checkbox
<input type="checkbox" id="needmemberpwd" name="needmemberpwd" value="0" onClick="checkmemberof(this)" class="checkstyle"> 
选中时request.getparameter("needmemberpwd")得到的是0,没选择得到是NULL
<input type="checkbox" id="needmemberpwd" name="needmemberpwd" value="1" onClick="checkmemberof(this)" class="checkstyle"> 
选中时request.getparameter("needmemberpwd")得到的是1,没选择得到是NULL
如果两个checkbox
<input type="checkbox" id="needmemberpwd" name="needmemberpwd" value="0" onClick="checkmemberof(this)" class="checkstyle"> 
<input type="checkbox" id="needmemberpwd" name="needmemberpwd" value="1" onClick="checkmemberof(this)" class="checkstyle"> 
如果你选中一个,那request.getparameter("needmemberpwd")得到的就是选中的这个checkbox的value值,如果两个都选中那得到的是排在第一个的checkbox的值,
如果2个都没选,那得到的就是NULL
下面是两个简单的例子程序
test1.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'test1.jsp' starting page</title>
</head>
<body>
<form action="test2.jsp">
<input type="checkbox" id="needmemberpwd" name="needmemberpwd" value="0"> 
<input type="checkbox" id="needmemberpwd" name="needmemberpwd" value="1"> 
<input type="submit" value="submit">
</form>
</body>
</html>

test2.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
String value1 = request.getParameter("needmemberpwd");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'test2.jsp' starting page</title>
</head>
  
<body>
This is my JSP page. <%=value1 %><br>
</body>
</html>




------解决方案--------------------
JS逻辑有问题
JScript code

function checkmemberof(o