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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 01:23:47  来源:igfitidea点击:

Error: Calendar cannot be resolved in JSP

javajspdateget

提问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

Calendaris in a java.utilpackage. 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" %>