当前位置:   article > 正文

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

contenttype cannot be resolved

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

运行结果如图:

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/人工智能uu/article/detail/735000
推荐阅读
相关标签
  

闽ICP备14008679号