当前位置: 移动技术网 > IT编程>开发语言>Java > jsp有两个按钮来控制Timer的开始和结束方法

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

2017年12月08日  | 移动技术网IT编程  | 我要评论

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的开始和结束方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网