jsp有两个按钮来控制Timer的开始和结束方法
1、jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
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< CODE> |
2、Controller
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
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
1
2
3
4
5
6
7
8
9
10
|
package net.spring.utils;
import java.util.TimerTask;
public class CameraTask extends TimerTask {
@Override
public void run() {
//dosomthing;
}
}
|
jsp复习资料汇总
[JSP]2017年1月24日asp教程编程辅导汇总
[ASP]2016年12月2日JSP快速入门教程汇总
[JSP]2016年12月2日jsp基本用法和命令汇总
[JSP]2016年10月3日ASP编码教程:如何实现/使用缓存
[ASP]2015年4月15日