This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Dynamic Servlet

 
Carsten Rasmussen
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
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate 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.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • 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
Eclipse IDE Hibernate 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic