This discussion is archived
8 Replies Latest reply: Jan 12, 2007 9:53 AM by 807599 RSS

Reading a File !!!

807599 Newbie
Currently Being Moderated
I've to read a file from the directories and display it on the jsp page in the tabular format. Whenever it encounters , or " it should be putted into the particular column and when it encounters the next line it should go to the next row. I'm not able to get this thing, i've tried with bufferedreader. Suppose here is the example :

i've the text file in the format as:
123, abc, ert , wert , 2/3/2007 10:34, 2/12/2006 12:24 , 23
235, aer, er, asdff, 2/12/2006 12:12, 3/1/2007 10:24 , 12
........

i want to display in the jsp page as tabular format as:

Roll No. name desig post access date deliver date count
--------------------------------------------------------------------------------------------------
123 abc ert wert 2/3/2007 10:34 2/1/2007 12:24 23
235 aer er asdff 2/12/2006 12:12 3/1/2007 10:24 12
--------------------------------------------------------------------------------------------------

please help me out !!!!!
in advance thanks a lot..............
  • 1. Re: Reading a File !!!
    800282 Newbie
    Currently Being Moderated
    Ok you tried it with a BufferedReader. What went wrong? (other than "it didn't work", or "I got errors")
  • 2. Re: Reading a File !!!
    807599 Newbie
    Currently Being Moderated
    BufferedReader

    Read through that and see if you can figure it out.
  • 3. Re: Reading a File !!!
    807599 Newbie
    Currently Being Moderated
    i'm able to read a file and even write it on the jsp page, but i'm not able to display it on the jsp page as tabular format. How can i segregate it contents and display it on each column and after that in each row?? m bit confused , could u please send me the any code or some kind of hint to achieve this problem.....
  • 4. Re: Reading a File !!!
    masijade Explorer
    Currently Being Moderated
    You are going to have to parse the information and create an HTML table out of it, obviously, if you wish to display a table on HTML.

    As you read each line split it up using either the split method from String, or a regeular expression, as befits the data structure, then assign each of these as a TD and make the entire line a TR and add the TABLE start and end tags.
  • 5. Re: Reading a File !!!
    807599 Newbie
    Currently Being Moderated
    i'm able to read a file and even write it on the jsp
    page, but i'm not able to display it on the jsp page
    as tabular format. How can i segregate it
    contents and display it on each column and after that
    in each row?? m bit confused , could u please send
    me the any code or some kind of hint to achieve this
    problem.....
    HINT: quit your job and let someone who is capable do it.
  • 6. Re: Reading a File !!!
    807599 Newbie
    Currently Being Moderated
    <table border="1">
    <tr>
    <td><b>Id</b></td>
    <td><b>Name</b></td>
    <td><b>Age</b></td>
    <td><b>Sex</b></td>
    </tr>
    <%
    
    String datas[] = new String[]{"1, name1, age1, sex1", "2, name2, age2, sex2"};
    
    int r = datas.length;
    int c = 4;
    
    for(int i=0; i<r; i++){
    
         %><tr><%
    
         String data[] = datas.split(","); 

         for(int j=0; j<c; j++){
              
              %><td><%=data[j]%></td><%
         }

         %></tr><%
    }
    %>
    </table>Cheers
  • 7. Re: Reading a File !!!
    807599 Newbie
    Currently Being Moderated
    the inline java in jsp is fugly. use jstl tags.
  • 8. Re: Reading a File !!!
    807599 Newbie
    Currently Being Moderated
    the inline java in jsp is fugly. use jstl tags.
    I believe aniseed has something to say about jstl tags.