Results 1 to 2 of 2
  1. #1
    reubenmk is offline Member
    Join Date
    Aug 2010
    Posts
    6
    Rep Power
    0

    Exclamation Display data from list on same jsp page

    I have a jsp page in which i have few parameters for the user to select and on clicking submite
    it shud display the data on the same jsp page from the servlet to which it goes
    so these are the lines i used to go back to the jsp page


    Servlet
    -----------------
    DBUtilLogin dbTrade= new DBUtilLogin();
    List TradeDet=dbTrade.getTradesDate(paramMap);

    request.setAttribute("TradeDet", TradeDet);
    request.getRequestDispatcher("mainjsp.jsp").forwar d(request, response);


    DBUtilLogin.java
    ---------------------
    public List getTradesDate(Map<String, String> paramMap){
    ResultSet rstd=null;
    Statement sttraded=null;
    if (con==null) init();

    try{
    String inves=paramMap.get("inves");
    String frmdt=paramMap.get("from_date");
    String todt=paramMap.get("to_date");
    System.out.println("the investor id is retrieved "+inves);
    StringBuilder sqltd=new StringBuilder("select * from trades where investor ='"+inves+"' and to_date(trd_date,'YYYYMMDD')>= to_date('"+frmdt+"', 'DD/MM/YYYY') and to_date(trd_date,'YYYYMMDD')<= to_date('"+todt+"', 'DD/MM/YYYY')");
    sttraded=con.createStatement();
    rstd=sttraded.executeQuery(sqltd.toString());
    List tradeListd=new ArrayList();

    Map obj;
    while(rstd.next()){
    obj=new HashMap();

    obj.put("TRD_DATE", rstd.getString(1));
    obj.put("MRKT", rstd.getString(2));
    obj.put("QTY", rstd.getString(7));
    obj.put("SEC", rstd.getString(9));
    tradeListd.add(obj);
    }
    return tradeListd;

    }catch (SQLException ex) {
    //Logger.getLogger(DBUtilLogin.class.getName()).log( Level.SEVERE, null, ex);
    ex.printStackTrace();
    return null;
    }


    }

    mainjsp.jsp
    ---------------

    The data displays here if i give this
    <table>
    <c:forEach var="TradeDet" items="${TradeDet}">
    <tr>
    <td>"${TradeDet}</td>

    </tr>
    </c:forEach>
    </table>

    But its in an ugly format and not table format.
    "[{SEC=fff, QTY=1000, MRKT=0, TRD_DATE=20110209}, {SEC=ttt, QTY=40000, MRKT=0, TRD_DATE=20120209} ...and so on it goes like this

    i want it to display in a proper table format.
    How do i display each row with proper data?


    SEC QTY MRKT TRD_DATE
    fff 1000 0 20110209
    ttt 4000 0 20110209

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default Re: Display data from list on same jsp page

    You'll need to write out each inidividual attribute.
    At the moment all you've asked it to do is print each TradeDet, which will use the toString method.
    In fact, you;re looping over the TradeDet array, and assigning each entry to a variable called TradeDet...which might lead to tsome confusion in itself.
    Then you print out the TradeDet array.

Similar Threads

  1. JSP page display
    By cnu.nandhikonda@gmail.com in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 02-01-2012, 10:48 AM
  2. how can i display my data on jsp page in struts2
    By shekhar16 in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 03-04-2011, 09:14 AM
  3. Display image on jsp page
    By shuchi.vishnoi in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 11-30-2010, 12:46 PM
  4. Replies: 8
    Last Post: 12-29-2008, 07:12 AM
  5. How to display Tabuler Data in J2EE application on jsp page
    By AMATYA-CHANAKYA in forum Advanced Java
    Replies: 2
    Last Post: 04-23-2008, 05:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •