I haven't looked at the method write data as u are not calling it
anywhere

The eofsw in the jsp seems redundant in this piece of code. You are also
not making any use of the start and end parameters in the read data
function.

These are the things I noted:

1. You are fetching all the data at once with the read data function
2. You are then writing the data in the JSP page.

Keeping this into consideration yes it will come as a single string. You
need to design the bean and jsp interaction so that u retrieve the data
one row at a time in the bean and loop thro the display in jsp.

Also read up on file IO and String and StringBuffer and not coding with
break on exception, your code needs a lot of optimization.

Regards,

Amit Ghaste


-----Original Message-----
From: A mailing list about Java Server Pages specification and reference
[mailto:[EMAIL PROTECTED] On Behalf Of Snehal Pandya
Sent: Wednesday, July 16, 2003 9:56 PM
To: [EMAIL PROTECTED]
Subject: Help me

Friends,

I am in a problem.
I want to write message log .
For that  I am using Random access file.
I want outout on the JSP.

My JSP file is

<%@ page import="java.io.*,java.lang.*" %>
<%@ page import="p1.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>  </TITLE>
</HEAD>
<BODY>
<jsp:useBean id="r1" class="p1.RandomFileFinal" scope="session" />
<form name="dataView" method= "post" action = "fileView.jsp">
<%
      boolean eofsw=false;
      out.println("Reading...");
    String  b="";
      try{
            if(!eofsw){
                  out.println("Entered the if..");
                  b=r1.readData(0,4);
                  out.println(b);
                  out.println("<br>");
            }
      }
      catch(Exception e){
            out.println("Error in the file");
      }


 %>
</form>
</BODY>
</HTML>

And Java File is

package p1;
import java.io.*;

public class RandomFileFinal
{
      public void writeData1(String type, String origin, String msg)
      {
            byte b=0;
            long maxsize = 500;
            String hdrMsg="0|0|0|*";
            String str="";
            byte dtlMsg[] = new byte[20];
            byte hdrData[] = new byte[30];
            RandomAccessFile rs= null;
            String sub[] = new String[4];
            int l=0,k=0,i=0;
            long hdrSize =0;
            long remHdr =0,remDetail=0;
            int cur=0;
            try{
                  rs= new RandomAccessFile("c:/FileLog.dat","rw");

                  if ( rs.length()==0){
                        rs.writeBytes(hdrMsg);
                  }
                  else{
                        rs.seek(0);
                        while(true){
                              b=rs.readByte();
                              char c = (char)b;
                              if (c=='*')
                              {
                                    hdrSize = rs.getFilePointer();
                                    remHdr=30-hdrSize;
                                    break;
                              }
                              str+=c;
                        }
                        while(l<str.length()){
                              k = str.indexOf("|",l);
                              sub[i] = str.substring(l,k);
                              l=k+1;
                              i++;
                        }
                        long l1 = rs.length();
                        sub[1]=String.valueOf(l1);
                        cur = Integer.parseInt(sub[2]);
                        if (cur==99){
                              cur= 0;
                        }
                        else{
                              cur++;
                        }
                        sub[2]=String.valueOf(cur);
                        rs.setLength(maxsize);

hdrMsg=String.valueOf(maxsize)+"|"+sub[1].trim()+"
|"+sub[2].trim()+"|*";
                        hdrData= hdrMsg.getBytes();
                        rs.seek(0);
                        rs.write(hdrData);
                        rs.seek(0);
                        rs.skipBytes(30+cur*20);
                        type+=origin.trim()+msg.trim();
                      dtlMsg =type.getBytes();
                        rs.write(dtlMsg);
                        rs.close();
                  }
            }
            catch(IOException e){
                  System.out.println("Error in Write Data and in the
file
cration");
                  //rs.close();
            }


      }

      public String readData(int start, int end)
      {
            int cur=0;
            byte b=0;
            int i=0,j =0;
            String dataRet ="";
            boolean eofsw = true;
            String str="";
            System.out.println(start);
            byte[] data = new byte[20];
            try{
                  RandomAccessFile rs= null;
                  long hdrSize =0;
                  rs= new RandomAccessFile("c:/FileLog.dat","r");
                  rs.seek(0);
                  char tests;

                  rs.seek(0);
                  rs.skipBytes(30+(start*20));
                  while(eofsw){
                        str="";
                        if(start >= end ){
                              break;
                        }
                        try{
                              for(j = 0; j<=2000;j++){
                                    tests= (char)rs.readByte();
                                    System.out.print(tests);
                                    str+=tests;
                              }

                              start++;
                        System.out.println(str);

                        }
                        catch(EOFException eof){
                              eofsw = false;
                              System.out.println("This is Error ");

                      }
                        rs.close();
                        return(str);

                  }


            }catch(IOException ie){
                        System.out.println("Can't open the File  ");
            }



               return(null);
      }


}

My problem is I am not getting out put record by record it is comming in
the one string.

Please help me
Thanks in advance

Snehal
------------------------------------------------------------------------
---------------------------------

No one in this world has been honored for what they received.
They were honored for what they gave.

========================================================================
===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".

Some relevant archives, FAQs and Forums on JSPs can be found at:

 http://java.sun.com/products/jsp
 http://archives.java.sun.com/jsp-interest.html
 http://forums.java.sun.com
 http://www.jspinsider.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".

Some relevant archives, FAQs and Forums on JSPs can be found at:

 http://java.sun.com/products/jsp
 http://archives.java.sun.com/jsp-interest.html
 http://forums.java.sun.com
 http://www.jspinsider.com

Reply via email to