jsp接收复选框参数的问题,在线等.急!

gjk11 2009-05-07 10:12:41
test.html

<html>
<head>
</head>
<body>
<form action="test2.jsp" method="post">
姓名:<input type="text" name="na" />
兴趣:<input type="checkbox" name="che" value="篮球">篮球
<input type="checkbox" name="che" value="网球">网球
<input type="checkbox" name="che" value="足球">足球
<input type="checkbox" name="che" value="游泳">游泳
<input type="checkbox" name="che" value="乒乓球">乒乓球<br>
<input type="submit" value="提交" />
</form>
</body>
</html>

test2.jsp

<%@ page contentType="text/html;charset=gbk"%>
<html>
<head>
</head>
<body>
<%
request.setCharacterEncoding("gbk");
String name=request.getParameter("na");
String xingqu[] =request.getParameterValues("che");
%>
<h1>用户名为:<%=name%></h1>
<h1>兴趣爱好:
<%
for(int i=0;i<che.length;i++)
{
%>
<%=xingqu[i]%>
<%
}
%>
</h1>
</body>
</html>

我这是按照一个视频上的代码写的,视频讲解上的可以运行,为什么我的老提示错误哪(另种写法我会可以运行,就是这段哪里出错了):

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 14 in the jsp file: /35.jsp
che.length cannot be resolved to a type
11: <h1>用户名为:<%=name%></h1>
12: <h1>兴趣爱好:
13: <%
14: for(int i=0;i<che.length;i++)
15: {
16: %>
17: <%=xingqu[i]%>

...全文
75 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
天剑斋主 2009-05-07
  • 打赏
  • 举报
回复
che 这个变量你没有定义哦。把test2.jsp里的循环改成用xingqu[]来控制次数或者定义一下che这个变量吧。
  • 打赏
  • 举报
回复
[Quote=引用楼主 gjk11 的帖子:]
test.html

<html>
<head>
</head>
<body>
<form action="test2.jsp" method="post">
姓名: <input type="text" name="na" />
兴趣: <input type="checkbox" name="che" value="篮球">篮球
<input type="checkbox" name="che" value="网球">网球
<input type="checkbox" name="che" value="足球">足球
<input type="checkbox" name="che" value="游泳">游泳
<input type="checkbox" name="che" value="乒…
[/Quote]
org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 14 in the jsp file: /35.jsp
che.length cannot be resolved to a type

for(int i=0;i <che.length;i++)
你这里che没有定义啊,你只是在jsp页面中对复选框name设置che,但是并不能引用啊
不是一种类型
你应该在<%%>里面来设置
String[] che=reqeust.getParameterValues("che");
这样试试
steryzone 2009-05-07
  • 打赏
  • 举报
回复
应该是

for(int i=0;i <xingqu.length;i++)

xu54647265 2009-05-07
  • 打赏
  • 举报
回复
废话,你的CHE在哪声明的?
明显你没声明这个变量

81,092

社区成员

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

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