Error: Calendar cannot be resolved in JSP

I tried setting the date in JSP, like what I was looking for before, but that didn't work. Here is my code.

<%@ 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 did he say "Calendar cannot be allowed"? Where is the mistake?

+5
source share
3 answers

Calendaris in the package java.util. You are missing an import.

+7
source

The updated code should look like this:

<%@ 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()));
    %>
+3
source

import the Calendar class as shown below

<%@ page import="java.util.Calendar" %>
+2
source

All Articles