jsp checkbox问题
1.jsp
<%@ page language="Java" contentType="text/html" %>
<html>
<body bgcolor="white">
<form action="2.jsp">
<input type="checkbox" name="fruits" value="Apple">Apple<br>
<input type="checkbox" name="fruits" value="Banana">Banana<br>
<input type="checkbox" name="fruits" value="Orange">Orange<br>
<input type="submit" value="Enter">
</form>
2.jsp
<%
String[] picked = request.getParameterValues("fruits");
%>
You picked the following fruits:<%=picked%>
2.jsp页面该怎么修改才能正确显示1.jsp传来的值????
问题点数:20、回复次数:13Top
1 楼edei2004(涛)回复于 2005-04-13 16:02:21 得分 0
You picked the following fruits:<%=picked%>
这种写法是不对的,picked是数组,是一个对象,你<%=picked%>就是打印一个对象是不对的,你可以这样写:<%=picked[i]%>,然后在外面加个循环就OK了
Top
2 楼TZW1212(文文)回复于 2005-04-13 16:12:46 得分 0
应为我最终想要的是将picked插入到数据库里面!!所以不知道picked能不能把值正确的插入到数据库里面,如果不行该怎么解决???Top
3 楼TZW1212(文文)回复于 2005-04-13 16:52:55 得分 0
<%
String[] picked = request.getParameterValues("fruits");
if (picked != null)
{
for (int i = 0;i < picked.length; i++)
{ %>
out.println(picked[i]);
<% }
} else
{%>
out.println ("none");
<%}
%>
You picked the following fruits:<%=picked[i]%>
我是这样写的,picked[i]有问题。。请大家帮我改改!!Top
4 楼AreamArgentateOfWing(梦幻银翼)回复于 2005-04-13 16:59:03 得分 0
多余部分:You picked the following fruits:<%=picked[i]%>Top
5 楼AreamArgentateOfWing(梦幻银翼)回复于 2005-04-13 16:59:17 得分 0
多余部分:You picked the following fruits:<%=picked[i]%>Top
6 楼lilyjk2003(lilyjk2003)回复于 2005-04-13 17:11:32 得分 0
i的作用域是for循环内部,所以在外面用会有问题Top
7 楼TZW1212(文文)回复于 2005-04-13 17:18:27 得分 0
1.jsp
<input type="checkbox" name="fruits" value="中国">中国<br>
2.jsp
<%@ page
language = "java"
contentType = "text/html; charset=gb2312"
%>
<%
String[] picked = request.getParameterValues("fruits");
if (picked != null)
{
for (int i = 0;i < picked.length; i++)
{
out.println(" "+picked[i]);
}
} else
{
out.println ("none");
}
%>
怎么解决中文传递中在2.jsp乱码问题!!!
Top
8 楼AreamArgentateOfWing(梦幻银翼)回复于 2005-04-13 17:30:25 得分 0
用unicode写"中国"就不会出现乱码Top
9 楼TZW1212(文文)回复于 2005-04-13 17:52:46 得分 0
是在1.jsp上这样加吗??
charset=unicode
还是不行。。。。。。。Top
10 楼zbulrush(老实巴交)回复于 2005-04-13 18:12:41 得分 0
str = new String ( str .getBytes ("ISO8859_1" ) , "GBK" )Top
11 楼TZW1212(文文)回复于 2005-04-14 08:39:27 得分 0
str 是个数组改怎么办???picked[i] 怎么转换Top
12 楼AreamArgentateOfWing(梦幻银翼)回复于 2005-04-14 09:05:09 得分 20
"中国"的unicode是中国Top
13 楼TZW1212(文文)回复于 2005-04-14 11:23:45 得分 0
哪如果我有很多词组要写在checkbox里面哪又怎么办???不可能没一个都去找它的unicode把??Top




