永发信息网

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

答案:2  悬赏:20  手机版
解决时间 2021-01-23 07:35
<%@ 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
最佳答案
在JSP中对于需要使用的类,都需要import。在JSP的上部通过指令标签page引入你使用的类。
<%@ page import="java.io.File"%>
全部回答
<%@ 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>
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
在东莞市只工作了一个月能领取失业金吗
wwe布洛克.莱斯纳 年薪多少万美金
我锻已经造冲到375.请问 风暴使者这把武器怎
判断一种社会制度的建立或消亡是进步还是倒退
在excel的VB编辑器中调试时出现"必须有启动窗
业余踢球的如何挑选足球鞋,有哪些经典款式值
晋城金村羴羴生态园怎么走?
跪求 带 览 字的诗词
平方在电脑上怎么打出来
单选题韩愈在《师说》中讲到,“古之学者必有
天天富翁游戏里我加的好友怎么在我的好友列表
橙光游戏引歌一梦开头的音乐
单选题Comparedtotheparents’expectation,wh
膨胀剂能否防止混凝土开裂
用IE10无法正常显示复选框,网页上有乱码,滚
推荐资讯
电脑开启后第一次加载英雄联盟很慢,后面的就
如何看主板支持内存条
夕阳红茶社地址有知道的么?有点事想过去!
新缘保健养生馆(二分店)地址在什么地方,我要
单选题若黄赤交角由现状变至20°,则会引起的
魔域跑商技能哪里学
豪车盛宴汽车主题酒吧地址好找么,我有些事要
外婆的房子外孙有继承权吗?
一部日本漫画讲的是一个男孩穿越到游戏里面了
买电脑玩GTA5好,还是买PS4好还是PS3好纠结,
下列物质中,即含有离子键,又含有共价键的是
丹麦的语言是什么
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?