赞
踩
在eclipse中写了一个自动刷新时间的程序,
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<% response.setHeader("refresh","1"); %>
<%
Date today = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
out.print("当前时间是: "+sdf.format(today));
%>
</body>
</html>
上面运行后报错:Date cannot be resolved to a type!
SimpleDateFormat cannot be resolved to a type!
报错截图:
以下为解决方法:<%@ Date import="java.util.*" %>,导入上述Date即可。
改后的代码如下:
<%@ page language="java"
import="java.util.*,java.text.SimpleDateFormat"
contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<% response.setHeader("refresh","1"); %>
<%
Date today = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
out.print("当前时间是: "+sdf.format(today));
%>
</body
>
</html>
运行结果如图:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。