?1
response.setContentType(
"
text/html
"
);?
?2
??ServletOutputStream?os?
=
?response.getOutputStream();?
?3
??SimpleDateFormat?format?
=
?
new
?SimpleDateFormat(
"
yyyy-MM-dd?HH:mm:ss
"
);?
?4
??
while
?(
true
)?
{?
?5
???
try
?
{?
?6
????String?str?
=
?format.format(
new
?java.util.Date());?
?7
????str?
=
?
"
服務(wù)器當(dāng)前時(shí)間:
"
?
+
?str?
+
?
"
<BR>
"
;?
?8
????
byte
[]?pdu?
=
?str.getBytes();?
?9
????os.write(pdu);?
10
????os.flush();?
11
????System.out.println(Thread.currentThread().getName()?
+
?
"
??發(fā)送?
"
?
+
?str);?
12
????
try
?
{?
13
?????Thread.sleep(
3000
);?
14
????}
?
catch
?(InterruptedException?ex)?
{?
15
????}
?
16
???}
?
catch
?(IOException?e)?
{?
17
????System.out.println(?
18
?????Thread.currentThread().getName()?
+
?
"
??客戶端斷開連接
"
);?
19
????
break
;?
20
???}
?
21
??}

?2

?3

?4



?5



?6

?7

?8

?9

10

11

12



13

14



15

16



17

18

19

20

21
