3

I am getting the error in my eclipse mars. It won't show any pop up for that these errors. And I am able to successfully run even after the errors, though in this particular case that that is also a issue.

  1. I had to run my server again and again, it's not picking up changes.
  2. Why these red squiggly line.
  3. I am getting below error when trying to run this.

    Why red flags

Error:

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 13 in the jsp file: /HelloWorld.jsp
Date cannot be resolved to a type
10: 
11: <%
12: 
13: Date today = new java.util.Date();
14: 
15: String text = "Today's date is: " + today.toString();
16: %>
User
  • 483
  • 4
  • 19

3 Answers3

6

You need to import date-class or fully qualify both.

Either put this at the top of your page:

<%@ page import="java.util.Date" %>
....
Date today = new Date();

or:

java.util.Date today = new java.util.Date(); 
Denis Lukenich
  • 3,084
  • 1
  • 20
  • 38
3

You can't import Date class in your JSP page : Place following code at the top place of jsp page.

<%@page import="java.util.Date"%> 
Bhuwan Prasad Upadhyay
  • 2,916
  • 1
  • 29
  • 33
2

Your missing an import. Without that import Java/JSP "don't know" Date. There are to ways to deal with this error:

1.- Import Date on the top of your page, to tell your programm "where to find Date":

<%@page import="java.util.Date"%> 

2.- Or you could easily tell him it right in the line where you declaring the variable:

java.util.Date yourDate= new java.util.Date(); 

Note that if your using the second way it won't work for other variables than yourDate.

Felix Gerber
  • 1,615
  • 3
  • 30
  • 40