Application of complex Type JavaBean (array members) in JSP: Passing arrays between JSP pages

Source: Internet
Author: User
Tags array arrays return
js| Array | page
In the forum often see someone asked how to pass the array between JSP pages, in fact, with JavaBean is very easy to achieve.

Here's a simple example of what type of data structure can be passed as long as you follow JavaBean's game rules:

1: Write a test for Javabean:package Com.infoearth;public class jobbean{private int[] b;

/** * @return return B.  * * Public int[] Getb () {return b;}/** * @param b to set. */public void Setb (int[] b) {this.b = b;}}

2: In the first JSP page (note that the name of the text box is "B"): <form action= "managejob.jsp" method= "POST" ><table><tr>      <td width= "height=" > </td>        <td Width= "height=" ><input name= "B" type= "Text" size= "3" ></td>    <td width= "50" height= "><input" name= "B" type= "Text" size= "3" ></td>    <td width= "height=" 30 "><input name=" B "type=" Text "size=" 3 "></td>    <td width=" "height=" >< Input name= "B" type= "Text" size= "3" ></td>    <td width= "a" height= "" ><input name= "B" type= "Text" size= "3" ></td>    <td width= "height=" ><input name= "B" "type=" Text "size=" 3 "></td>    <td width=" height= "><input name=" B "type=" text "size= "3" ></td>    <td width= "height=" ><inputName= "B" type= "Text" size= "3" ></td>    <td width= "a" height= "" ><input name= "B" Type= "Text" size= "3" ></td>    <td width= "height= ><input" "Name=" "B" type= "text "Size=" 3 "></td>    <td width=" height= "><input name=" B "type=" Text "size=" 3 " ></td>  </tr></table><input type= "Submit" value= "submitted" ></form>

3: In the managejob.jsp page, you can accept this array, very simple, with Get method can be: <%@ 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>
<body>hello<%int[] Temp=jobinfo.getb () for (int i=0;i<temp.length;i++) {out.print (i+---"+temp[i]+" <br> ");

}

%></body>
Note the internal mechanism of the JavaBean: the name of the array named B in JavaBean, then in the first JSP, the text box that fills in array B must be named B, otherwise you won't get it! This is the JavaBean rules of the game Oh, I hope to help you


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.