jsp页面checkbox空值

wangxin016 2009-11-26 10:39:41
if (request.getParameter("hobby") == null || request.getParameter("hobby").equals(""))
out.println("<I>No Value</I>");
String[] paramValues = request.getParameterValues("hobby");
if (paramValues.length == 1) {
String paramValue = paramValues[0];
out.print(paramValue);
}
else {
out.println("<UL>");
for(int i=0; i<paramValues.length; i++){
out.println("<LI>" + paramValues[i] + "</LI>");
}
out.println("</UL>");
}

当checkbox这个控件全不选的时候,就报空异常。是不是第一个if判断的不对呢?应该怎么弄,困扰我半天了
...全文
134 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
JWQ525727 2009-11-26
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wanghailong0115 的回复:]
Java codeif (request.getParameter("hobby")==null|| request.getParameter("hobby").equals(""))
out.println("<I>No Value</I>");else {
String[] paramValues= request.getParameterValues("hobby");if (paramValues.length==1) {
String paramValue= paramValues[0];
out.print(paramValue);
}else {
out.println("<UL>");for (int i=0; i< paramValues.length; i++) {
out.println("<LI>"+ paramValues[i]+"</LI>");
}
out.println("</UL>");
}
}
应该这样
[/Quote]

这样应该是对的;或者在你的第一个if后价格reutrn就行了
zzzfff2008 2009-11-26
  • 打赏
  • 举报
回复
楼主的判断写错啦,应该是非空的时候才做处理啊
huminghua 2009-11-26
  • 打赏
  • 举报
回复
你在之前做下判断不就OK啦!判断如果为空就返回撒!
feitianya 2009-11-26
  • 打赏
  • 举报
回复
if (request.getParameter("hobby") == null
||"".equals( request.getParameter("hobby")))
out.println("<I>No Value</I>");
else {
String[] paramValues = request.getParameterValues("hobby");
if (paramValues.length == 1) {
String paramValue = paramValues[0];
out.print(paramValue);
} else {
out.println("<UL>");
for (int i = 0; i < paramValues.length; i++) {
out.println("<LI>" + paramValues[i] + "</LI>");
}
out.println("</UL>");
}
}
这样试一下
wanghailong0115 2009-11-26
  • 打赏
  • 举报
回复
lz去试试吧 应该不会报异常了
wanghailong0115 2009-11-26
  • 打赏
  • 举报
回复
if (request.getParameter("hobby") == null
|| request.getParameter("hobby").equals(""))
out.println("<I>No Value</I>");
else {
String[] paramValues = request.getParameterValues("hobby");
if (paramValues.length == 1) {
String paramValue = paramValues[0];
out.print(paramValue);
} else {
out.println("<UL>");
for (int i = 0; i < paramValues.length; i++) {
out.println("<LI>" + paramValues[i] + "</LI>");
}
out.println("</UL>");
}
}

应该这样
swandragon 2009-11-26
  • 打赏
  • 举报
回复
String[] paramValues = request.getParameterValues("hobby");
if(paramValues == null)
out.println("<I>No Value</I>");
else {
……
}
道光2008 2009-11-26
  • 打赏
  • 举报
回复
头昏
应该为:
if (request.getParameter("hobby") != null && !request.getParameter("hobby").equals(""))
out.println("<I>No Value</I>");
String[] paramValues = request.getParameterValues("hobby");
if (paramValues.length == 1) {
String paramValue = paramValues[0];
out.print(paramValue);
}
else {
out.println("<UL>");
for(int i=0; i<paramValues.length; i++){
out.println("<LI>" + paramValues[i] + "</LI>");
}
out.println("</UL>");
}
道光2008 2009-11-26
  • 打赏
  • 举报
回复
if(request.getParameterValues("hobby") != null) {String[] paramValues = request.getParameterValues("hobby");
if (paramValues.length == 1) {
String paramValue = paramValues[0];
out.print(paramValue);
}
else {
out.println("<UL>");
for(int i=0; i<paramValues.length; i++){
out.println("<LI>" + paramValues[i] + "</LI>");
}
out.println("</UL>");
}}
hyf0541210 2009-11-26
  • 打赏
  • 举报
回复
if (request.getParameter("hobby") == null || "".equals(request.getParameter("hobby"))
out.println("<I>No Value</I>");
else {
String[] paramValues = request.getParameterValues("hobby");
if (paramValues.length == 1) {
String paramValue = paramValues[0];
out.print(paramValue);
}
else {
out.println("<UL>");
for(int i=0; i<paramValues.length; i++){
out.println("<LI>" + paramValues[i] + "</LI>");
}
out.println("</UL>");
}

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧