欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-10-20 13:07:38
1、jsp <%@ page language="java" contenttype="text/html; charset=utf-8" pageen...

1、jsp

<%@ page language="java" contenttype="text/html; charset=utf-8"
 pageencoding="utf-8"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/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 net.spring.controller;

import java.util.timer;

import net.spring.utils.cameratask;
import net.spring.utils.hktest;

import org.springframework.stereotype.controller;
import org.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 net.spring.utils;

import java.util.timertask;

public class cameratask extends timertask {
 @override
 public void run() {
 //dosomthing;
 }
}


以上这篇jsp有两个按钮来控制timer的开始和结束方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。