Javascript 对于get请求,如何启动程序,然后使用另一个get请求停止它?
我正在运行一个使用java和tomcat的网站。在高层,我试图做的是将一个开始按钮路由到一个java方法,该方法对其他资源进行无休止的调用。当我想停止那个程序时,我会按下停止按钮 我已经找到了开始部分,但无法停止它,因为我认为get请求页面的状态无法保存。在这个类中,我有一些全局变量,我想每次我发出get请求时,它们都会被重置。我怎样才能防止这种情况发生Javascript 对于get请求,如何启动程序,然后使用另一个get请求停止它?,javascript,java,html,http,routes,Javascript,Java,Html,Http,Routes,我正在运行一个使用java和tomcat的网站。在高层,我试图做的是将一个开始按钮路由到一个java方法,该方法对其他资源进行无休止的调用。当我想停止那个程序时,我会按下停止按钮 我已经找到了开始部分,但无法停止它,因为我认为get请求页面的状态无法保存。在这个类中,我有一些全局变量,我想每次我发出get请求时,它们都会被重置。我怎样才能防止这种情况发生 @Path("/myresource") public class MyResource { continuousMethod sample
@Path("/myresource")
public class MyResource {
continuousMethod sample = new continuousMethod()
boolean collecting = false;
/**
* Method handling HTTP GET requests. The returned object will be sent
* to the client as "text/plain" media type.
*
* @return String that will be returned as a text/plain response.
*/
@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("/collect")
public String startCollection() throws URISyntaxException {
System.out.println("Made it here");
sample.start();
collecting = true;
return "Collecting";
}
@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("/stopcollect")
public String stopCollection() {
sample.close();
collecting = false;
return "Finished collecting!";
//return "Not collecting";
}
}
使用
会话
而不是全局变量。感谢您的输入,指导我了解我想做得更好的地方。