所以我不知道如何正确导入 java 类。我正在使用eclipse tomcat 7和liferay。在 liferay 中是一个包含 img 文件的目录,我将使用 java 打开该目录。这很好用(本地),我得到一个带有路径的数组。所以我将在 jsp 中的 liferay 中创建一个 portlet,并在 jsp 中获取数组。有任何想法吗?我的jsp:
<%@ page import ="OpenDir" %>
<%@ page import="java.io.File"%>
<%=
OpenDir.Dir()
%>
我的爪哇:
package life_ray;
import java.io.File;
public class OpenDir {
public static void Dir() {
int i = 0;
File directory = new File(
"C:\\Users\\Public\\Pictures\\Sample Pictures\\");
File[] contents = directory.listFiles();
for (File f : contents) {
f.getAbsolutePath();
i++;
}
String[] name = new String[i];
i = 0;
for (File f : contents) {
name[i] = f.getAbsolutePath();
i++;
}
i = 0;
for (File f : contents) {
name[i] = f.getAbsolutePath();
System.out.println("<img src=\"" + name[i] + "\" alt=\"\">");
i++;
}
}
}
so here is my error:
Caused by: org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 14 in the generated java file
Only a type can be imported. life_ray.OpenDir resolves to a package
An error occurred at line: 7 in the jsp file: /view.jsp
OpenDir cannot be resolved
4: <body>
5:
6: <%=
7: OpenDir.Dir()
8: %>
9:
10: