我在两个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上运行?
答案 0 :(得分:0)
为我工作:
“右键单击你的项目并选择Properties(它位于底部......可能)。部署程序集是其中一个页面。如果带有NTP类的jar不在WebContent / WEB-INF / lib或其他内容中在服务器上,确保它在此页面上。“
回答