有没有让jsp接收复选框的参数值更方便的方案呢?
在一个页面中有一组同名复选框,我在另一个页面中得到这组复选框提交的多选参数值
例如:<form name="form1" action="xxx.jsp" method="post">
<input type="checkbox" name="checkbox2" value="1">
<input type="checkbox" name="checkbox2" value="2">
<input type="checkbox" name="checkbox2" value="3">
</form>
假如我选中了第一个和第二个,我在xxx.jsp中得到他们的值
那么checkbox2里面就包括了"1","2",它们是可以通过函数分开的,只是我也只是在ASP里边用过,对于JSP我还是新手
String[] checkbox2 = request.getParameterValues("checkbox2");
String[] result = request.getParameterValues("checkbox2");
for (int i = 0; result != null && i < result.length; i++){
String resultStr = reault[i];
}jsp有没提供更好的方案来解决这个问题呢?
在一个页面中有一组同名复选框,我在另一个页面中得到这组复选框提交的多选参数值
例如:<form name="form1" action="xxx.jsp" method="post">
<input type="checkbox" name="checkbox2" value="1">
<input type="checkbox" name="checkbox2" value="2">
<input type="checkbox" name="checkbox2" value="3">
</form>
假如我选中了第一个和第二个,我在xxx.jsp中得到他们的值
那么checkbox2里面就包括了"1","2",它们是可以通过函数分开的,只是我也只是在ASP里边用过,对于JSP我还是新手
String[] checkbox2 = request.getParameterValues("checkbox2");
String[] result = request.getParameterValues("checkbox2");
for (int i = 0; result != null && i < result.length; i++){
String resultStr = reault[i];
}jsp有没提供更好的方案来解决这个问题呢?
解决方案 »
- 系统分析,系统设计,系统实施,系统测试,都分别是软件开发中的什么阶段?
- 如何把database里的数据在AWT画面中显示?请举例?
- 请教一个算法,一个数组 分别按从大到小 和从小到大输出
- 关于java的简体繁体转换
- 急!!!!有人懂java懂正则表达式的朋友过来看看.
- 在线等!!高手进来指点小弟!!
- 请问各位有没有在数据库中用过xpath查询,无论是oracle还是sqlserver什么的
- 请问如何用jni类来调用一个非java写的外部exe?谢谢!
- 如何用js 的得到一个html的 html代码
- 如何用java实现对com口的操作?请给出实例
- 《我在北大青鸟的180天》/Java部分/第一章
- 能否解释下何为对象序列化?
* Gets a list of long parameters.
* @param request The HttpServletRequest object, known as "request" in a
* JSP page.
* @param name The name of the parameter you want to get
* @param defaultNum The default value of a parameter, if the parameter
* can't be converted into a long.
*/
public static long[] getLongParameters(HttpServletRequest request,
String name, long defaultNum)
{
String[] paramValues = request.getParameterValues(name);
if (paramValues == null) {
return null;
}
if (paramValues.length < 1) {
return new long[0];
}
long[] values = new long[paramValues.length];
for (int i=0; i<paramValues.length; i++) {
try {
values[i] = Long.parseLong(paramValues[i]);
}
catch (Exception e) {
values[i] = defaultNum;
}
}
return values;
}