【问题标题】:Create JSP file in Eclipse using Apache Tomcat使用 Apache Tomcat 在 Eclipse 中创建 JSP 文件
【发布时间】:2021-12-02 00:16:50
【问题描述】:

这是我第一次使用 Eclipse 和 Tomcat。 我想添加一个包含以下 HTML/JSP 内容的index,jsp 文件。

<%@ 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>

错误:

java.util.Date cannot be resolved to a type

java.util.Date()&lt;/body&gt; 之前的行中引发错误

【问题讨论】:

  • &lt;%@ page import="java.util.Date" %&gt; 代替 &lt;%@ page import java.util.Date()%&gt; 有效吗?
  • 不,它不起作用

标签: java eclipse jsp tomcat


【解决方案1】:

试试下面的代码,

<%@ 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>

这里还有一件事,因为我们已经导入了 java.util.Date 类,然后在使用它时不需要使用完全限定名称。我们可以像这样直接使用它的类名

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-02
    • 1970-01-01
    • 1970-01-01
    • 2013-12-23
    相关资源
    最近更新 更多