checkbox 在jsp中的使用
本文作者:佚名
所属分类:网络编程
加入时间:2006-1-19
点击次数:396
<%@ page language="java" contentType="text/html" %>
<%@ page import="com.ora.jsp.util.*" %>
<html>
<body bgcolor="white">
<form action="checkbox.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>
<%
String[] picked = request.getParameterValues("fruits");
if (picked != null && picked.length != 0) {
%>
You picked the following fruits:
<form>
<input type="checkbox" name="fruits" value="Apple"
<%= ArraySupport.contains(picked, "Apple") ?
"checked" : "" %> >Apple<br>
<input type="checkbox" name="fruits" value="Banana"
<%= ArraySupport.contains(picked, "Banana") ?
"checked" : "" %> >Banana<br>
<input type="checkbox" name="fruits" value="Orange"
<%= ArraySupport.contains(picked, "Orange") ?
"checked" : "" %> >Orange<br>
</form>
<% } %>
</body>
</html>
有可能value是中文的话会出现乱码,我的pageEcoding和contentType都改成GBK了还是不行
String a = request.getAttribute("name");
byte[] b = a.getBytes("ISO-8859-1");
a = new String(b);
那就把数组的每个元素都重新转换一下