0

Hi, I am new at this...

I am trying to display data from a text file to a JSP file and I'm using BufferedReader to do this but having problems getting to the file. Which directory should I put the text file? Should I add anything to web.xml to reference to it? Here is the error I am getting... Any help is appreciated.

09:32:58,655 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 4 in the jsp file: /PPOS.jsp
BufferedReader cannot be resolved to a type
1: <%@ page language="java" contentType="text/html;charset=UTF-8"%>
2:
3: <%
4: BufferedReader input = new BufferedReader(new FileReader("c:\\InputData.txt"));
5: String line = "";
6: String strOutputDir="";
7: String PriceBookVal="";


An error occurred at line: 4 in the jsp file: /PPOS.jsp
BufferedReader cannot be resolved to a type
1: <%@ page language="java" contentType="text/html;charset=UTF-8"%>
2:
3: <%
4: BufferedReader input = new BufferedReader(new FileReader("c:\\InputData.txt"));
5: String line = "";
6: String strOutputDir="";
7: String PriceBookVal="";


An error occurred at line: 4 in the jsp file: /PPOS.jsp
FileReader cannot be resolved to a type
1: <%@ page language="java" contentType="text/html;charset=UTF-8"%>
2:
3: <%
4: BufferedReader input = new BufferedReader(new FileReader("c:\\InputData.txt"));
5: String line = "";
6: String strOutputDir="";
7: String PriceBookVal="";


Stacktrace:
        at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
        at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
        at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:415)
        at org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
        at org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
        at org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
        at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)

Edited by peter_budo: Replacing colour highlight with code text

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by parry_kulk
0

The error is that "BufferedReader cannot be resolved to a type". It is caused because you have not imported the corresponding libraries.
Import the libraries in JSP as
<@page import="java.io.BufferedReader">
...
and so on

Also the file can be placed anywhere on the server if you are using absolute filepaths.
If you keep the files within the webapp than you can even access it as,
<%=getServletContext().getRealPath("InputData.txt")%>

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.