|
![]() |
名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
在论坛上常看见有人问如何在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"> </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的游戏规则呵呵,但愿对你有帮助 返回类别: 教程 上一教程: Java 正则表达式自义bean 下一教程: 使用hibernate扩展工具hbm2java根据配置文件生成持久化对象类(2.1.2) 您可以阅读与"复杂类型javabean(数组成员)在jsp中的运用:在jsp页面间传递数组"相关的教程: · JAVABEAN在JSP中的应用 · STRUTS下JSP页面传递复选框值技巧 · jsp页面中的有关字符集 这样 · JSP/SERVLET 中的汉字编码问题 · JSP开发入门(三)--JSP与JAVABEAN |
![]() ![]() |
快精灵印艺坊 版权所有 |
首页![]() ![]() ![]() ![]() ![]() ![]() ![]() |