Results 1 to 2 of 2
  1. #1
    shrvasu is offline Member
    Join Date
    Oct 2008
    Posts
    1
    Rep Power
    0

    Default how to display the contents of textfile in textarea at runtime using JSP

    plaese help me out!!!!!!:confused:
    Hi, my code is reading only the last line from the textfile and displaying in the textraea. i want that it should display whole textfile in the textarea on buton click event.i'm attaching the code:
    <%@ page import= "java.lang.*, java.io.*, java.util.*" %>
    <%
    File file = new File("E:/MISReport/public_html/test.txt");
    FileInputStream fis = null;
    BufferedInputStream bis = null;
    DataInputStream dis = null;
    String s1=null;
    %>
    <HTML>
    <HEAD><TITLE>Select Report Group</TITLE>
    <script language="javascript">
    function goBack()
    {
    document.selectreportgroup.action="log.jsp";
    document.selectreportgroup.submit();
    }
    </script>
    <script language="javascript">
    function dosubmit()
    {
    <%
    fis = new FileInputStream(file);
    bis = new BufferedInputStream(fis);
    dis = new DataInputStream(bis);
    for(int i=0;i<dis.available();i++){
    %>document.getElementById("txtAreaLog").value="<%= dis.readLine()%>";
    <%}%>
    }
    </script>
    </HEAD>
    <BODY bgColor=white leftMargin=0 topMargin=0 marginheight="0" marginwidth="0" onload="dosubmit()">
    <%
    String username = (String)session.getAttribute("passuname");
    String password = (String)session.getAttribute("passpass");
    if(username==""||password=="")
    {%>
    <jsp:forward page="index.jsp"></jsp:forward>
    <%}
    %>
    <FORM name="selectreportgroup" method="post" >
    <div align="center">
    <div align="right">[ <A href="logout.jsp" style=""><font style="font-family:verdana; font-size:70%;" color="blue"><b>L</b>ogout</font></A> ]</div>
    <IMG src="images/lds.gif" alt="">
    <TABLE width="100%" align="center" bgColor="white" border="0">
    <tr>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td nowrap='nowrap' height="10" align="center" colspan="7" style="font-family:verdana; font-size:70%; background-color: #EA0000; color: white;" ><b>LOG GROUP</b></td>
    </tr>
    </TABLE>
    <BR>
    <table width="60%" border="0.0" style="font-family:Verdana, Arial, Helvetica, sans-serif">
    <TR>
    <td>
    <textarea name="txtAreaLog" cols="120" rows="20" readonly="readonly" title="log area"> </textarea>
    </td>
    <TR>
    <TR>
    <TD align="center">
    <input style="font-family:verdana; font-size:100%;" type="button" value="Go Back" onclick="javaScript:goBack();">
    <INPUT style="font-family:verdana; font-size:100%;" type="reset" value=" Clear ">
    <input style="font-family:verdana; font-size:100%;" type="button" value="First" onclick="dosubmit(report_type.value);"/>
    <input style="font-family:verdana; font-size:100%;" type="button" value="Previous" onclick="dosubmit(report_type.value);"/>
    <INPUT style="font-family:verdana; font-size:100%;" type="button" value="Next" onclick="dosubmit(report_type.value);">
    <input style="font-family:verdana; font-size:100%;" type="button" value="Last" onclick="dosubmit(report_type.value);"/>
    </TD>
    </TR>
    </table>
    </div>
    </FORM>
    </BODY>
    </HTML>

  2. #2
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    Define StringBuffer s,then read line by line the text file and appending each line to s,then after the loop :
    document.getElementById("txtAreaLog").value=<%=s.t oString()%>;

Similar Threads

  1. ECG plot in a textfile
    By samson in forum Java 2D
    Replies: 13
    Last Post: 01-28-2012, 04:02 PM
  2. Replies: 17
    Last Post: 07-13-2009, 05:44 AM
  3. Inserting a Table in a TextFile?
    By Keerti in forum Advanced Java
    Replies: 5
    Last Post: 11-19-2008, 04:31 PM
  4. Search TextFile
    By gsupriyarao@yahoo.com in forum Advanced Java
    Replies: 5
    Last Post: 04-11-2008, 11:03 AM
  5. Textfile and GUI problems
    By saytri in forum New To Java
    Replies: 2
    Last Post: 12-21-2007, 04:08 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
  •