java 错误:无法在 JSP 中解析日历
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10516145/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error: Calendar cannot be resolved in JSP
提问by greenthunder
I tried to get date in JSP like what I searched before, but it didn't work. Here is my code.
我试图像我之前搜索的那样在 JSP 中获取日期,但是没有用。这是我的代码。
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*, java.text.*;" errorPage="" %>
<%!
DateFormat tipe = new SimpleDateFormat("EEE, MMM d, ''yy");
Calendar cal = Calendar.getInstance();
%>
<%
out.print(tipe.format(cal.getTime()));
%>
Why it said "Calendar cannot be resolved"? Where's the mistake?
为什么它说“日历无法解决”?错在哪里?
回答by Tarlog
Calendar
is in a java.util
package. You are missing import.
Calendar
在一个java.util
包中。您缺少导入。
回答by Garbage
Updated code should look like:
更新后的代码应如下所示:
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.util.*, java.text.*;" errorPage="" %>
<%!
DateFormat tipe = new SimpleDateFormat("EEE, MMM d, ''yy");
Calendar cal = Calendar.getInstance();
%>
<%
out.print(tipe.format(cal.getTime()));
%>
回答by Balaswamy Vaddeman
import Calendar class like below
像下面这样导入日历类
<%@ page import="java.util.Calendar" %>