jsp有两个按钮来控制Timer的开始和结束方法

网络编程 2021-07-05 11:23www.168986.cn编程入门
狼蚁网站SEO优化长沙网络推广就为大家带来一篇jsp有两个按钮来控制Timer的开始和结束方法。长沙网络推广觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随长沙网络推广过来看看吧

1、jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
 pageEncoding="UTF-8"%>
<%@taglib uri="http://.springframework./tags/form" prefix="form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://.w3./TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">
function st(){
 window.location.href="startCamera.html" rel="external nofollow" ;
}

function en(){
 window.location.href="cancelCamera.html" rel="external nofollow" ;
}

</script>
</head>
<body>
<input type="button" value="开始" onclick="st()"/><input type="button" value="结束" onclick="en()"/>
</body>
</html>


2、Controller

package .spring.controller;

import java.util.Timer;

import .spring.utils.CameraTask;
import .spring.utils.HKTest;

import .springframework.stereotype.Controller;
import .springframework.web.bind.annotation.RequestMapping;

@Controller
public class HKController {

 public Timer timer = null;
 public CameraTask mCameraTask = null;
 public static boolean status = false;

 @RequestMapping("startCamera")
 public String startCamera() {
 if (!status) {
//  HKTest.getInstance().login();

  if (timer == null) {
  timer = new Timer();
  }

  if (mCameraTask == null) {
  mCameraTask = new CameraTask();
  }

  timer.schedule(mCameraTask, 0, 1000);
  status = true;
 }

 return "camera";
 }

 @RequestMapping("cancelCamera")
 public String cancelCamera() {
 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

package .spring.utils;

import java.util.TimerTask;

public class CameraTask extends TimerTask {
 @Override
 public void run() {
 //dosomthing;
 }
}


以上这篇jsp有两个按钮来控制Timer的开始和结束方法就是长沙网络推广分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持狼蚁SEO。

Copyright © 2016-2025 www.168986.cn 狼蚁网络 版权所有 Power by