代码在NetBeans中正常工作,但在Eclipse中不能正常工作



我在两个ide中尝试了以下jsp文件。它在NetBeans中工作得很好,但在Eclipse中不能工作。该程序将从NTP服务器获取时间。

代码如下

 <%-- 
Document   : GetNTP
Created on : May 21, 2013, 2:21:29 PM
Author     : Maximin
--%>
<%@page import="java.net.InetAddress"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import ="java.util.Date"%>
<%@page import="org.apache.commons.net.ntp.NTPUDPClient"%>
<%@page import="org.apache.commons.net.ntp.TimeInfo"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
</head>
<body>
    <h1><%
    String TIME_SERVER = "time.nist.gov";
    NTPUDPClient timeClient = new NTPUDPClient();
    InetAddress inetAddress = InetAddress.getByName(TIME_SERVER);
    TimeInfo timeInfo = timeClient.getTime(inetAddress);
    long returnTime = timeInfo.getReturnTime();
    Date time = new Date(returnTime);
            SimpleDateFormat sdf= new SimpleDateFormat("dd-MM-yyyy");
            out.println(sdf.format(time));
    %></h1>
</body>
</html>

当我在eclipse中运行这个时,我得到

org.apache.jasper.JasperException: Unable to compile class for JSP: 
An error occurred at line: 17 in the generated java file
Only a type can be imported. org.apache.commons.net.ntp.NTPUDPClient resolves to a package
An error occurred at line: 18 in the generated java file
Only a type can be imported. org.apache.commons.net.ntp.TimeInfo resolves to a package
 An error occurred at line: 18 in the jsp file: /GetTime.jsp
NTPUDPClient cannot be resolved to a type
15: <body>
16: <h1><%
17:         String TIME_SERVER = "time.nist.gov";
18:         NTPUDPClient timeClient = new NTPUDPClient();
19:         InetAddress inetAddress = InetAddress.getByName(TIME_SERVER);
20:         TimeInfo timeInfo = timeClient.getTime(inetAddress);
21:         long returnTime = timeInfo.getReturnTime();

为什么会这样?

我该怎么做才能让它在Eclipse上运行?

为我工作:

"右键单击你的项目并选择属性(它可能在底部…)。部署程序集是其中一个页面。如果包含NTP类的jar文件不在WebContent/WEB-INF/lib中,或者不在服务器上,请确保它在本页上。"

回答

相关内容

  • 没有找到相关文章

最新更新