Remote.jsp代码:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Remote Value</title>
</head>
<body>
<%
File remote = new File("D:\\test.txt");
FileReader fr = new FileReader(remote);
int ch;
while((ch = fr.read()) != -1)
out.println("<p>" + (char)ch + "</p>");
fr.close();
%>
</body>
</html><jsp:include page="Remote.jsp"/>被嵌入到另一个jsp中,路径是正确的。但每次我都会得到一个异常。
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 11 in the jsp file: /Remote.jsp File cannot be resolved to a type发布于 2011-04-01 21:44:11
当Remote.jsp自身编译失败时,可能会出现此异常。您可以通过直接打开文件来测试它,而不是将其包含在另一个页面中。然后,您将看到有关原因的明确异常。据我所知,您至少缺少了Remote.jsp中的java.io.*导入。
<%@page import="java.io.*" %>与无关的具体问题,这是一个糟糕的方法。它不仅可能导致另一个JSP中的HTML语法无效(不能嵌套<html>等等)。考虑使用从磁盘读取文件并将其流式传输到响应的servlet。然后你就可以这样做
<div style="white-space: pre;">
<jsp:include page="fileservlet/test.txt" />
</div>https://stackoverflow.com/questions/5513892
复制相似问题