把所有的input放在form标签中,<form action="第二个jsp页面">,通过表单提交把选中的值提交到第二个jsp页面,在第二个jsp页面中通过request.getParameterValues("products");取得所有选中的值
解决方案 »
- JSP页面输出数据库查询信息
- oracle查询问题
- myeclipse导入已有工程后,hibernate.cfg.xml双击打开提示错误
- javascript基础
- 求助,sql 语句
- 请教一下如何将<jsp:usebean>中的类导入进来
- 我用jspsmartupload做上传程序,有一个语法错误
- 快救救疯子吧。。。。连接池问题。
- 急!如何做一个矩阵beans?
- 怎么把datetime的时间显示出只要年、月、日?在查询数据库时怎样查一段时间内的内容?
- 急啊!!!知道一个Session的ID,如何取得此Session对象?但此Session不一定是当前用户的
- Connection refused这是什么错误?
那么反过来,判断一下,不就可以得到没勾的吗?
第2个页面那里 接受参数的语句比如 products=request.getParameterValues("products");
其中products就是你需要的参数。
能否直接在第一个页面中生成这个未勾选数组,
或者在第二个JSP页面直接 (全部变量名--已勾选的变名名),那么全部变量又该如何产生呢?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>彩E客服系统——用户管理</title>
<style type="text/css">
<!--
.style3 {color: #FF0000}
-->
</style>
</head>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;}.line1{text-align: center;font-size: 9pt "宋体"}
.line0{text-align: center;font-size: 9pt "宋体"; background-color:#ECF8FB}
-->
</style>
<link rel='stylesheet' type='text/css' href='../css.css'>
<SCRIPT language=JavaScript >
function getchekValue()
{
var i="hello";
var chekValue="";
for(var j=0;j<document.frm1.max.value;j++)
{
i=document.frm1.RightID[j].checked;
if (i)
{
if (j==0)
{
chekValue=chekValue+'1';
}
else{
chekValue=chekValue+',1';
}
}
else{
if (j==0)
{
chekValue=chekValue+'0';
}
else{
chekValue=chekValue+',0';
}
}
}
document.frm1.chekValue.value=chekValue;
alert(chekValue);
}</SCRIPT>
<body>
<form name="frm1" method="post" action="">
<table width="700"><tr><td bgcolor="#4B6B7A"><font color="#ffffff">系统管理</font></td></tr><table><p>
<table width="710" height="131" border="1" cellpadding="0" cellspacing="0" bordercolor="#ABC1DA">
<tr>
<td height="17" bgcolor="#CCCCCC"><div align="center"><span class="style3">注意</span>:权限修改后需重新登录才能生效!</div></td>
</tr>
<tr>
<td height="18" bgcolor="#CCCCCC"><div align="center">用户名:<font size=2 color=#ff0000><strong>fengli</strong></font></div></td>
</tr>
<tr>
<td>
<table width="598" border="1" align="center" cellpadding="0" cellspacing="0" bordercolordark="#ffffff" bordercolorlight="#44aacc">
<tr>
<td width="103" height=25 bgcolor="#44aacc"><div align="center">选择</div></td>
<td width="236" bgcolor="#44aacc"><div align="center">权限名称</div></td>
<td width="259" bgcolor="#44aacc"><div align="center">权限描述</div></td>
</tr>
<tr class="line1">
<td><div align="center">
<input type="checkbox" id="RightID" name="RightID" value="1" checked>
</div></td>
<td> 子目录</td>
<td> 子目录隶属于单用户查询1.1</td>
</tr>
<tr class="line0">
<td><div align="center">
<input type="checkbox" id="RightID" name="RightID" value="1" checked>
</div></td>
<td> 子目录</td>
<td> 子目录隶属于单用户查询1.2</td>
</tr>
<tr class="line1">
<td><div align="center">
<input type="checkbox" id="RightID" name="RightID" value="1" checked>
</div></td>
<td> 子目录</td>
<td> 子目录隶属于包月查询2.1.1</td>
</tr>
<tr class="line0">
<td><div align="center">
<input type="checkbox" id="RightID" name="RightID" value="1" checked>
</div></td>
<td> 子目录</td>
<td> 子目录隶属于包月查询2.1.2</td>
</tr>
<tr class="line1">
<td><div align="center">
<input type="checkbox" id="RightID" name="RightID" value="1" checked>
</div></td>
<td> 子目录</td>
<td> 子目录隶属于单张查询2.2.1</td>
</tr>
<tr class="line0">
<td><div align="center">
<input type="checkbox" id="RightID" name="RightID" value="1" checked>
</div></td>
<td> 子目录</td>
<td> 子目录隶属于单张查询2.2.2</td>
</tr>
<tr class="line1">
<td><div align="center">
<input type="checkbox" id="RightID" name="RightID" value="1" checked>
</div></td>
<td> 子目录</td>
<td> 子目录隶属于内容制作的3.1</td>
</tr>
<tr class="line0">
<td><div align="center">
<input type="checkbox" id="RightID" name="RightID" value="1" checked>
</div></td>
<td> 子目录</td>
<td> 子目录隶属于内容制作的3.2</td>
</tr>
<tr class="line1">
<td><div align="center">
<input type="checkbox" id="RightID" name="RightID" value="1" checked>
</div></td>
<td> 子目录</td>
<td> 子目录隶属于内容制作的3.3</td>
</tr>
<tr class="line0">
<td><div align="center">
<input type="checkbox" id="RightID" name="RightID" value="1" checked>
</div></td>
<td> 子目录</td>
<td> 子目录隶属于系统管理的4.1</td>
</tr>
<tr class="line1">
<td><div align="center">
<input type="checkbox" id="RightID" name="RightID" value="1" checked>
</div></td>
<td> 子目录</td>
<td> 子目录隶属于系统管理的4.2</td>
</tr>
<tr class="line0">
<td><div align="center">
<input type="checkbox" id="RightID" name="RightID" value="1" checked>
</div></td>
<td> 子目录</td>
<td> 子目录隶属于系统管理的4.3</td>
</tr>
<tr class="line1">
<td><div align="center">
<input type="checkbox" id="RightID" name="RightID" value="1" checked>
</div></td>
<td> 子目录</td>
<td> 子目录隶属于系统管理的4.4</td>
</tr>
<tr class="line0">
<td><div align="center">
<input type="checkbox" id="RightID" name="RightID" value="1" >
</div></td>
<td> 子目录</td>
<td> 子目录隶属于系统查询2.3</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<input type="button" name="submit" value="确 定" class="bgbutton" onclick="getchekValue()">
<input type="button" name="button" value="返 回" class="bgbutton" onclick="backup()">
<input type="hidden" id="max" name="max" value=14>
<input type="hidden" id="userName" name="userName" value=fengli>
<input type="hidden" id="chekValue" name="chekValue">
</td>
</tr>
</table>
</form>
</body>
</html>
当未勾选checkbox的数据库记录,Updata时在记录的SF中写入“0”,
所以想知道未勾选的和已勾选的,同时我知道已勾选的JSP传递方法,但不知道未勾选的是如何判断,和传递的。请高手帮忙
我个人觉得在这个例子中使用数组就是一个很好的方法,只是我不知道该如何去判断,感谢aoplo(新札师弟),我粗粗看了一下,你的方法很好,要使他适合我的程序,
可能还需要一点改变,谢谢。
当未勾选checkbox的数据库记录,Updata时在记录的SF中写入“0”,
所以想知道未勾选的和已勾选的,同时我知道已勾选的JSP传递方法,但不知道未勾选的是如何判断,和传递的。请高手帮忙
你可以先update打钩的checkbox,再执行update 表名 set SF='0' where SF <> 1
难难难。
我现在只是在想如何能返回全部勾选与未勾选的全部数据,至今未有人回复。
难难难。
我现在只是在想如何能返回全部勾选与未勾选的全部数据,至今未有人回复。
哦~~你可以默认SF为0啊~~
或者把checkbox的value设为A,B,C,D,……
再在第2张JSP页面里面解析字符串:int [] c = new int[N]; //N为复选框的个数,我想26个应该够了吧,不够再把ASCII码'Z'后面的符号加进去
int i;
for(i=0;i<N;i++) c[i] = 0; //初始化每个复选框状态
if(request.getParameterValues("name")!=null) {
String SF = request.getParameterValues("name");
char a;//临时变量
int b;
//检索哪些复选框被选中
for(i=0;<SF.length();i++) {
a = SF[i];
if(a<'A'||a>'Z') continue; //容错
b = a - 'A';
c[b] = 1; //1为被选中状态
}
}