eclipse FileNotFoundException与JSP兼容,但Java代码可以正常工作
我正在尝试使用jsp和java来显示从csv读取到网站的信息。我使用的是Tomcat v9。0和Eclipse
当在java中运行java代码时,它会将csv数据读入歌曲对象的ArrayList中。但是,在运行jsp文件时,它会抛出filenotfoundexception
原始java代码在“ReadBillboardCSV”的getter函数中读取和解析csv,如下所示:
public ArrayList<BillboardSong> getReadBillboardCSV() throws FileNotFoundException {
Reader in = new FileReader("testFile.csv");
ArrayList<BillboardSong> readSongs = new ArrayList<BillboardSong>();
try {
Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(in);
for (CSVRecord record : records) {
BillboardSong newSong = new BillboardSong();
readSongs.add(newSong);
newSong.setPosition(Integer.parseInt(record.get(0)));
我的servlet调用getter,然后设置属性
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession ses = request.getSession(true);
ReadBillboardCSV readData = new ReadBillboardCSV();
ArrayList<BillboardSong> songsArray = readData.getReadBillboardCSV();
ses.setAttribute("billboardArray", songsArray);
}
以下是jsp的主要部分:
<%
RequestDispatcher rd = request.getRequestDispatcher("/ServletOne");
rd.forward(request, response);
%>
当我在Tomcat上运行文件时,它无法读取文件,这有什么原因吗
共 (0) 个答案