0

両方の 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で実行するにはどうすればよいですか?

4

1 に答える 1