-1

hi i am new towards development especially java i have created jsp page and when i run that jsp page i can perform the task that i need but i want it to run some thing like service that when i run my project it will run my jsp page too but do not show any thing means jsp display .

Because i am just inserting data in data and there is nothing to display. Actually i am keep on ping some host in my jsp page by calling method in class that do it and keep on doing it automatically after some time by using

"<meta http-equiv="refresh" content="5">"

so it ping some host and insert its data in database

How would i do it like a service that it starts my desire work when i run project

Hopes for your Suggestions and please give some example to understand example code

  • you might want to explain by some example. it is hard to understand what you are asking\ – Aravind Yarram Jan 18 '12 at 04:42
  • @user1155394 - unfortunately, the combination of your poor English skills, the absence of any concrete details of your problem, and the absence of any clear questions makes this Question virtually unanswerable. – Stephen C Jan 18 '12 at 08:03

1 Answers1

1

What it sounds like is you have a JSP that inserts some data somewhere. And you want a java process that repeatedly calls this JSP page. This is a little odd, as I would java have the java process itself do the inserting and cut out the jsp middle-man, but whatever.

One very simple thing you can do is this:

import java.net.*;
import java.io.*;
public class MyClass {

public static void main(String [] args) throws Exception {
   while (true) {
     URL myJSPURL = new URL("http://server/my.jsp");  //url for your jsp
     BufferedReader in = new BufferedReader(
        new InputStreamReader(myJSPURL.openStream())); //open cnonection
     while (in.readLine() != null);  //read the data from the connection, discard it
     in.close();
     System.sleep(5000);  //sleep 5 seconds
    }
}
}

Of course, this is very simple. You can do more complex scheduling with a java.util.concurrent.ExecutorService

marathon
  • 6,497
  • 10
  • 56
  • 120