• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Java Dynamic Servlet

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well.. i got really good help on my last topic so here we go again.
I have searched the whole internet for a servlet like the one below who dynamic reads the file spitting out new content all the time.
Can anyone help on this one.

-- readfile.java



A shame you cant give eachother points cuz i would give 1000p for this one.
In my research i discovered that there are many ways of doing this function like.
If i just could repeat the function with delay or not without overload.



But i never managed to do it in anyway
your regards: Carsten Rasmussen
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I understand the question. What is it you are trying to do?
 
Carsten Rasmussen
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to dynamic read a txt file and get new data all the time from the file.
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So ... a request comes in, and the response consists of the contents of the file? At a quick glance, the servlet seems to do that. Which difficulty are you encountering? And what does the Thread.sleep code block have to do with it?
 
Carsten Rasmussen
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to read data.txt constantly like reading chat-data

Could be a way of delaying and do the function again over and over.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you want one request to generate n responses? That's not how HTTP works.

If its chat behavior you want you will need to use soemthing other than HTTP, which means an applet in the client, or AJAX to send multiple requests in the background.
 
Carsten Rasmussen
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured it out and now im gonna show it.

readfile.java


And the index.jsp with ajax.

 
Carsten Rasmussen
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May i add this for us Danish ( dk ) poeple
Instead of:

Do this:

In the readfile.java above.
 
A tiny monkey bit me and I got tiny ads:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic