XXX cannot be resolved to a type!报错已解决!jsp

在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>

运行结果如图:

猜你喜欢

转载自blog.csdn.net/weixin_41887276/article/details/83113765
今日推荐