永发信息网

jsp出现File cannot be resolved to a type的问题

答案:2  悬赏:20  手机版
解决时间 2021-01-23 07:35
  • 提问者网友:爱唱彩虹
  • 2021-01-22 12:07
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<html>
<body bgcolor="#csd96">
<P>
<font Size=6 color=purple>
This is readFile.jsp
</font>
</P>
<FONT Size=4>
<%
String s= request.getParameter("file");
File f=new File(s);
if(f.exists())
{
out.println("<BR>文件"+s+"的内容:");
FileReader in=new FileReader(f);
BufferedReader br=new BufferedReader(in);
String line=null;
while((line=br.readLine())!=null)
{
out.println("<BR>"+line);
}
}
else
{
%>
<jsp:forward page="error.jsp">
<jsp:param name="mess" value="File Not Found"/>
</jsp:forward>
<%
}
%>
</FONT>
</body>
</html>

出现问题:
Description Resource Path Location Type
File cannot be resolved to a type readFile.jsp shiyan2(2)/WebRoot line 12 JSP Problem
File cannot be resolved to a type readFile.jsp shiyan2(2)/WebRoot line 12 JSP Problem
FileReader cannot be resolved to a type readFile.jsp shiyan2(2)/WebRoot line 16 JSP Problem
FileReader cannot be resolved to a type readFile.jsp shiyan2(2)/WebRoot line 16 JSP Problem
最佳答案
  • 五星知识达人网友:狂恋
  • 2021-01-22 12:48
在JSP中对于需要使用的类,都需要import。在JSP的上部通过指令标签page引入你使用的类。
<%@ page import="java.io.File"%>
全部回答
  • 1楼网友:天凉才是好个秋
  • 2021-01-22 12:53
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%> <%@page import="java.io.FileReader"%> <html> <body bgcolor="#csd96"> <P> <font Size=6 color=purple> This is readFile.jsp </font> </P> <FONT Size=4> <% String s= request.getParameter("file"); java.io.File f=new java.io.File(s); if(f.exists()) { out.println("<BR>文件"+s+"的内容:"); java.io.FileReader in=new java.io.FileReader(f); java.io.BufferedReader br=new java.io.BufferedReader(in); String line=null; while((line=br.readLine())!=null) { out.println("<BR>"+line); } } else { %> <jsp:forward page="error.jsp"> <jsp:param name="mess" value="File Not Found"/> </jsp:forward> <% } %> </FONT> </body> </html>
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯