javabean里面如何取得jsp页面上的二维数组?

本来小弟是通过在jsp页面上开连续的对象来获取的

javabean里面收取代码:


// ks12G01D01.settantono((String)getRequestData().get("object_"+i)

jsp里的代码:

//<%or(int i; i<1000;i++){%>
<input type=
"hidden" name="object_<%= i%>“ value="">
}

不过这样写太占用资源,一旦对象开多了就会影响页面的速度,所以想用数组的方式来传递,但不知如何,请请指点?同时也向知道一下二维数组怎么传递,谢谢各位大虾!

不建议用数组,特别是在前台Jsp页面,一旦出错,无法定位,Jsp和数组都是极其脆弱的东西

使用struts的ActionForm ,使用Collection接受多个项目输入,开始花点力气,以后维护就方便。

谢谢banq大哥。

谢谢banq大哥

强烈反对不用数组!!!

我喜欢用数组,重用率极高,不存在出错不易定位的情况。
如果都包装成值对象,包来拆去,非常麻烦。
请看jsp


<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri=
"/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri=
"/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib prefix=
"c" uri="http://java.sun.com/jstl/core"%>
<html> <head>
<meta http-equiv=
"Content-Language" content="zh-cn">
<title>&Aring;&auml;&Ouml;&Atilde;&sup1;&Uuml;&Agrave;í</title>
<link rel=
"stylesheet" type="text/css" href="./style/style.css">
<script language=
"javaScript" src = "./script/script.js"></script>
<script language=
"javaScript" src = "./script/no_menu.js"></script>
</head>

<body background=
"./images/bg.gif">
<table border=
"0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="96%" id="AutoNumber1" >
<tr>
<td width=
"20%" height="37"></td>
<td width=
"60%" align="center" height="37"><span>&Aring;&auml;&Ouml;&Atilde;&Aacute;&ETH;±í</span></td>
<td width=
"20%" height="37"></td>
</tr>
</table>
<form name=
"PageForm" action="queryAction.do?modelNo=receiveDevice" method="post">
<table border=
"1" cellpadding="0" cellspacing="0" align="center" class="dtable" style="border-collapse: collapse" bordercolor="#111111" width="100%">
<tr class=
"rowColor1" onMouseOver = "overTr(this,'#0000FF')" onMouseOut = "outTr(this,'#000000')">
<td colspan=
"" nowrap class = "td_c"></td>
</tr>
<tr>
<td class =
"bhtd_c" nowrap width="0%">&ETH;ò &ordm;&Aring;</td>
<td class =
"bhtd_c" nowrap width="0%">&Oacute;&brvbar;&Oacute;&Atilde;&acute;ú&Acirc;&euml;</td>
<td class =
"bhtd_c" nowrap width="0%">&micro;&Oslash;&Ouml;・</td>
<td class =
"bhtd_c" nowrap width="0%">&para;&Euml;&iquest;&Uacute;&ordm;&Aring;</td>
<td class =
"bhtd_c" nowrap width="0%">&Atilde;&Uuml;&Acirc;&euml;</td>

<td class=
"bhtd_c" nowrap width ="0%"><b><span lang="en">&iexcl;&Aacute;</span></b></td>
</tr><%String rowColor =
"rowColor1";int nn=1;%>
<logic:present name=
"pageData" scope="request">
<c:forEach items=
"${pageData}" var="row" varStatus="rowNumber" >
<tr class=<%=rowColor%> onMouseOver =
"overTr(this,'#0000FF')" onMouseOut = "outTr(this,'#000000')">
<td class =
"td_c" nowrap > <c:out value="${rowNumber.count}"/></td>
<c:forEach items=
"${row}" var="colum" varStatus="columNumber">
<td class =
"td_c" nowrap onclick="location.href='findAction.do?modelNo=receiveDevice&amp;primaryKey=<c:out value="${row[0]}"/>'" > <c:out value="${colum}"/></td>
</c:forEach>
<td class =
"td_c" nowrap width ="0%"><b><span lang="en">&iexcl;&Aacute;</span></b></td>
</tr>
<%rowColor = nn%2==0?
"rowColor1":"rowColor2";nn++;%>
</c:forEach>
</logic:present>
<tr class=&iexcl;°rowColor1&iexcl;± onMouseOver =
"overTr(this,'#0000FF')" onMouseOut = "outTr(this,'#000000')">
<td class =
"td_l" colspan="4" nowrap width ="0%">
<logic:present name=
"pageB" scope="request">
<tr class=&iexcl;°rowColor1&iexcl;± onMouseOver =
"overTr(this,'#0000FF')" onMouseOut = "outTr(this,'#000000')">
<td class =
"td_l" colspan="13" nowrap width ="0%">
<jsp:include page=
"/common/selectPage.jsp"/>
</tr>
</logic:present>


</tr>

</table>

</form>
</body>
</html>

在action 中 处理
String[][] pageData = pageBean.getPageData(sqlQuery, pageNumber);
并把pageData放在request里,然后传到刚才的jsp中。

这样,所有绝大多数业务都可以重用jsp视图,和处理pagBean的action.
模块性好,重用性极高,你自己比较一下吧。