checkbox 在jsp中的使用

 本文做者:佚名html

所属分类:网络编程 java

加入时间:2006-1-19编程

点击次数:396 数组

<%@ page language="java" contentType="text/html" %>网络

<%@ page import="com.ora.jsp.util.*" %>jsp

<html>ui

<body bgcolor="white">spa

<form action="checkbox.jsp">orm

<input type="checkbox" name="fruits" value="Apple">Apple<br>htm

<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);

那就把数组的每一个元素都从新转换一下