Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Display data from list on same jsp page

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy 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

    PLease help!!


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Display data from list on same jsp page

    Why don't you create table then?

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Display data from list on same jsp page

    i am creating table..but how do i display each value in each column...i dont know to read teh data individually...

  4. #4
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Display data from list on same jsp page

    Data is in the List? And why can't you just place each index of Data in each column?

  5. #5
    Junior Member
    Join Date
    Feb 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Display data from list on same jsp page

    u mean to place each index of data in each column in the jsp page??cud u show me a piece of that code?

  6. #6
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Display data from list on same jsp page

    Didn't you ever create a table before?
    Place a loop and inside loop, draw columns, giving them the values for List's index.

  7. #7
    Junior Member
    Join Date
    Feb 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Display data from list on same jsp page

    problem is solved.Thanks
    this piece of code in the mainjsp.jsp solved it.
    <%
    List trad=(List)request.getAttribute("TradeDet");
    if (trad!=null){
    out.println("<table border=\"1\">");
    for (int i=0;i<trad.size();i++)
    {
    Map obj=(Map) trad.get(i);

    out.println("<tr>");
    out.println("<td>"+obj.get("TRD_DATE")+"</td>");
    out.println("<td>"+obj.get("MRKT")+"</td>");
    out.println("<td>"+obj.get("SEC")+"</td>");
    out.println("<td>"+obj.get("QTY")+"</td>");
    out.println("</tr>");
    }
    out.println("</table>");
    }
    %>

    The problem i was facing was i dint put the if null loop check for the list. so after logging in it used to give exception. Now after putting the if loop it checks if the list is empty or not. if empty it displays the remaining tags.else it displays data.

  8. #8
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Display data from list on same jsp page

    if is not a loop but a conditional statement.

Similar Threads

  1. How to display data from list into web browser with JSTL foreach loop ?
    By banana in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: November 13th, 2011, 06:50 PM
  2. How to display OS configuration ffrom JSF page?
    By rcbandit2 in forum JavaServer Pages: JSP & JSTL
    Replies: 5
    Last Post: August 4th, 2011, 06:59 PM
  3. how can i display my data on jsp page in struts2
    By shekhar16 in forum Web Frameworks
    Replies: 0
    Last Post: March 4th, 2011, 06:26 AM
  4. Display Servlet Output into JSP Page
    By DanBrown in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: February 28th, 2011, 10:34 AM
  5. Get data from web page
    By inmar32 in forum Web Frameworks
    Replies: 4
    Last Post: July 21st, 2010, 10:09 AM