1、jsp%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%%@taglib uri="http://www...
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的开始和结束方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
				 沃梦达教程
				
			本文标题为:jsp有两个按钮来控制Timer的开始和结束方法
				
        
 
            
        
             猜你喜欢
        
	     - JSP 制作验证码的实例详解 2023-07-30
 - 基于Java Agent的premain方式实现方法耗时监控问题 2023-06-17
 - ExecutorService Callable Future多线程返回结果原理解析 2023-06-01
 - 深入了解Spring的事务传播机制 2023-06-02
 - Spring Security权限想要细化到按钮实现示例 2023-03-07
 - SpringBoot使用thymeleaf实现一个前端表格方法详解 2023-06-06
 - Springboot整合minio实现文件服务的教程详解 2022-12-03
 - Java中的日期时间处理及格式化处理 2023-04-18
 - JSP页面间传值问题实例简析 2023-08-03
 - Java实现顺序表的操作详解 2023-05-19
 
						
						
						
						
						
				
				
				
				