• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

复杂类型javabean(数组成员)在jsp中的运用:在jsp页面间传递数组

发布: 2007-7-01 18:47 | 作者: admin | 来源: | 查看: 14次 | 进入软件测试论坛讨论

领测软件测试网
在论坛上常看见有人问如何在jsp页面间传递数组,其实用javabean是很容易实现的.

下面给个简单的例子,只要遵循javabean的游戏规则,什么类型的数据结构都可以传递:

1:写一个测试用的javabean:package com.infoearth;public class JobBean{private int[] b;

 /**  * @return 返回 b。  */ public int[] getB() {  return b; } /**  * @param b 要设置的 b。  */ public void setB(int[] b) {  this.b = b; }}

2:在第一个jsp页面中(注意文本框的name都是"b"):<form action="manageJob.jsp" method="post"><table><tr>     <td width="50" height="30">&nbsp;</td>        <td width="50" height="30"><input name="b" type="text" size="3"></td>    <td width="50" height="30"><input name="b" type="text" size="3"></td>    <td width="50" height="30"><input name="b" type="text" size="3"></td>    <td width="50" height="30"><input name="b" type="text" size="3"></td>    <td width="50" height="30"><input name="b" type="text" size="3"></td>    <td width="50" height="30"><input name="b" type="text" size="3"></td>    <td width="50" height="30"><input name="b" type="text" size="3"></td>    <td width="50" height="30"><input name="b" type="text" size="3"></td>    <td width="50" height="30"><input name="b" type="text" size="3"></td>    <td width="50" height="30"><input name="b" type="text" size="3"></td>    <td width="50" height="30"><input name="b" type="text" size="3"></td>  </tr></table><input type="submit" value="提交"></form>

3:在manageJob.jsp页面中,就可以接受这个数组了,很简单,用get方法就可以得到:<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*, com.infoearth.*"

errorPage="" %><jsp:useBean id="jobInfo" class="com.infoearth.JobBean" scope="request"><jsp:setProperty name="jobInfo" property="*"/></jsp:useBean><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>无标题文档</title></head>

<body>hello<%int[] temp=jobInfo.getB();for(int i=0;i<temp.length;i++){ out.print(i+"---"+temp[i]+"<br>");

}

%></body></html>

请注意javabean的内部机制:在javabean中命名的数组名为b,那么在第一个jsp中,填写数组b的文本框必须命名为b,否则就得不到!这是javabean的游戏规则呵呵,但愿对你有帮助

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网