Return array from java file to JSP

Discussion in 'JavaScript' started by melvinoyh, Jun 28, 2006.

  1. #1
    private class prgclm
    {
    	double wp;
    	double ln;
    	int cnt;
    }
     
    public void getChgDetail(){
    prgclm [] p = new prgclm[cnt];
    for(int j=0;j<cnt;j++)
    {
    	p[j] = new prgclm();
    }
    String detail = "SELECT * FROM mrladf "+
    					" WHERE pf_la_no = '"+laNo+"'"+
    					" AND pf_supl_typ = '"+suplTyp+"'"+
    					" AND pf_vo_no = 0";
                          int j=0;
        	ResultSet rs = null;
        	Conn db=new Conn();
        	rs = db.execSQL(detail);
        	while(rs.next()){
          		p[j].wp = rs.getDouble("pf_wp_no");
          		p[j].ln = rs.getDouble("pf_ln_no");
          		j=j+1;
          	}
                         db.close();
          	rs.close();
    }
    Code (markup):
    for example, in the java file, i create a private class call prgclm. and in the getChgDetail() function, i use sql to retrieve data and store them in an array. the array is
    prgclm [] p = new prgclm[cnt];

    after the data have been stored into the array that is prgclm [] p = new prgclm[cnt], how i gonna pass the array back to JSP page? does anyone know? becos i need to display the data at the JSP page there. thx>
     
    melvinoyh, Jun 28, 2006 IP
  2. scottj

    scottj Peon

    Messages:
    168
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You will probably get a better response to this by posting in the right forum. This particular forum is for Javascript only.
     
    scottj, Jul 1, 2006 IP
  3. titoni

    titoni Active Member

    Messages:
    965
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Take the java class as a javabean,in jsp you only need use jsp:usebean to retrieve the value.
    See javascript array tutorial at below link
    http://www.developerzone.biz/index.php?option=com_content&task=view&id=137&Itemid=45
     
    titoni, Jul 4, 2006 IP
  4. hotpop

    hotpop Peon

    Messages:
    2,059
    Likes Received:
    96
    Best Answers:
    0
    Trophy Points:
    0
    #4
    hotpop, Jul 4, 2006 IP
  5. AllYearFootball

    AllYearFootball Peon

    Messages:
    61
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I am typing this from memory, so I may have some details or syntax wrong, but you could try something like the following in your jsp page:

    <script>
    var myParrayWP = [
    <%
    for (int i = 0; i < p.length; ++i)
    {
    if (i > 0)
    {
    out.println(",");
    }
    out.print("\"" + p.wp + "\"");
    }
    %>
    ];

    you can also do the same thing for the ln attribute.


    Hope this helps.
    <%
     
    AllYearFootball, Jul 17, 2006 IP