jsp有两个按钮来控制Timer的开始和结束方法
1、jsp
<%@pagelanguage="java"contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%> <%@tagliburi="http://www.springframework.org/tags/form"prefix="form"%>Inserttitlehere functionst(){ window.location.href="startCamera.html"rel="externalnofollow"; } functionen(){ window.location.href="cancelCamera.html"rel="externalnofollow"; }
2、Controller
packagenet.spring.controller; importjava.util.Timer; importnet.spring.utils.CameraTask; importnet.spring.utils.HKTest; importorg.springframework.stereotype.Controller; importorg.springframework.web.bind.annotation.RequestMapping; @Controller publicclassHKController{ publicTimertimer=null; publicCameraTaskmCameraTask=null; publicstaticbooleanstatus=false; @RequestMapping("startCamera") publicStringstartCamera(){ if(!status){ //HKTest.getInstance().login(); if(timer==null){ timer=newTimer(); } if(mCameraTask==null){ mCameraTask=newCameraTask(); } timer.schedule(mCameraTask,0,1000); status=true; } return"camera"; } @RequestMapping("cancelCamera") publicStringcancelCamera(){ if(status){ if(timer!=null){ timer.cancel(); timer=null; } if(mCameraTask!=null){ mCameraTask.cancel(); mCameraTask=null; } //HKTest.getInstance().logout(); status=false; } return"camera"; } }
3、TimerTask
packagenet.spring.utils; importjava.util.TimerTask; publicclassCameraTaskextendsTimerTask{ @Override publicvoidrun(){ //dosomthing; } }
以上这篇jsp有两个按钮来控制Timer的开始和结束方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。