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 6 of 6

Thread: displaying dyanamic data on jsp while core engine is writing it on text file

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    4
    My Mood
    Amused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default displaying dyanamic data on jsp while core engine is writing it on text file

    hi i am trying to print data on jsp page in realtime scenario while another core engine is writing data into the file
    this is the jsp script let code code


    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <%@ page import="java.io.*"%>
    <%@ page import="java.util.*"%>
    <%@ page import="java.io.BufferedReader"%> 
    <%@ page import="java.io.FileNotFoundException"%> 
    <%@ page import="java.io.FileReader"%> 
    <%@ page import="java.io.IOException"%> 
    <%@ page import="java.util.ArrayList"%> 
    <%@ page import="java.util.List"%>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Reading File from a Location</title>
    </head>
    <body>
    <form >
     
     
    <%
    List<String> list=new ArrayList<String>();
     
     
    BufferedReader bufferedReader = null;
     
    try {
    String filename= "d:/test.txt";
    //Construct the BufferedReader object
    bufferedReader = new BufferedReader(new FileReader(filename));
     
    String line = null;
     
    while ((line = bufferedReader.readLine()) != null) {
    //Process the data, here we just print it out
     
    try {
    Thread.sleep(3000);//sleep for 1000 ms
    response.flushBuffer();
    System.out.println(line);
    out.println("\n" +line+ "\n");
    list.add(line);
    System.out.println(list);
    //out.println(list);
    list.clear();
     
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
     
    e.printStackTrace();
    }
     
    }
     
    } catch (FileNotFoundException ex) {
    ex.printStackTrace();
    } catch (IOException ex) {
    ex.printStackTrace();
    } finally {
    //Close the BufferedReader
    try {
    if (bufferedReader != null)
    bufferedReader.close();
    } catch (IOException ex) {
    ex.printStackTrace();
    }
    }
     
    %>
     
     
     
     
     
    </form>
     
     
     
    </body>
    </html>

    this d:/test.text basically is written from core engine after every stipulated time lets say every 3 secs
    while the file is written , this test.txt, i am not able to show the data are written simultaneously in real time scenario, im able to show it after the file is wriiten..

    please advise me, how to show the data on jsp in real time simultaneously when in the back hand , core engine is writing the data simultaneously


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: displaying dyanamic data on jsp while core engine is writing it on text file

    If you want to update a webpage dynamically - since the page is client side and jsp is server side - you will need to set up some sort of communication, typically through AJAX, which uses javascript to query a servlet/page and update the client side as needed.

  3. #3
    Junior Member
    Join Date
    May 2011
    Posts
    4
    My Mood
    Amused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: displaying dyanamic data on jsp while core engine is writing it on text file

    can u please provide me with some examples ..in this regard...as im new to ajax. i want to know how do we do it using ajax

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: displaying dyanamic data on jsp while core engine is writing it on text file


  5. #5
    Junior Member
    Join Date
    May 2011
    Posts
    4
    My Mood
    Amused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: displaying dyanamic data on jsp while core engine is writing it on text file

    PLease provide me with a working code...so that i can work directly on it.I am in real need for it

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: displaying dyanamic data on jsp while core engine is writing it on text file

    Did you take my advice and do a web search? There are thousands of code snippets, tutorials, and explanations all over the internet. We are not a code service and don't get paid to do this, but we are here to help you along the way...help which shouldn't take the place of making an effort to learn how to accomplish your task.

Similar Threads

  1. Help writing to a text file on a website!
    By straw in forum File I/O & Other I/O Streams
    Replies: 10
    Last Post: September 11th, 2011, 11:02 AM
  2. Issues with writing to text file
    By surfbumb in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 12th, 2011, 09:43 AM
  3. probleming writing multiple items to text file
    By gskimmel in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 9th, 2011, 08:41 PM
  4. Replies: 8
    Last Post: March 25th, 2011, 02:34 PM
  5. Writing to a specific line in a text file
    By The_Mexican in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 7th, 2011, 09:11 PM