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)

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")%>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.