简体   繁体   中英

Create JSP file in Eclipse using Apache Tomcat

This is my first time using Eclipse and Tomcat. I want to add an index,jsp file containing the following HTTML/JSP content.

<%@ page import java.util.Date()%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
    <head>
    <meta charset="ISO-8859-1">
    <title>Message of the Day Application</title>
    </head>
    <body bgcolor="green">
    <h1 align="center">Welcome to MOTD Application</h1>
    <h1 align="center">Version 2.0</h1>
    <h1>Message of the Day: Cloud Computing is Cooler!</h1>
    <h2>The date and time now is <%= new java.util.Date() %></h2>
</body>
</html>

Error:

java.util.Date cannot be resolved to a type

Error raised for the java.util.Date() in the line prior to </body>

Try below code,

<%@ page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
    <head>
    <meta charset="ISO-8859-1">
    <title>Message of the Day Application</title>
    </head>
    <body bgcolor="green">
    <h1 align="center">Welcome to MOTD Application</h1>
    <h1 align="center">Version 2.0</h1>
    <h1>Message of the Day: Cloud Computing is Cooler!</h1>
    <h2>The date and time now is <%= new Date() %></h2>
</body>
</html>

Also one more thing here as we have imported java.util.Date class then no need to use fully qualified name while using it. We can use it directly with the class name like this <%= new Date() %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM