The easy option would be just to supply a link to the file. Assuming it's just a text file, when the user clicks on the link, the browser should render the file contents on screen or pop up the download window.
If you want to display the file contents within your
JSP page (a textarea for example) you'll need to do something server side with your
JSP/Servlet code.
Somthing like this should do it:
- Code: Select all
public static String getStringFromFile(String path)
throws IOException {
StringBuffer buff = new StringBuffer(5000);
BufferedReader in = new BufferedReader(new FileReader(path));
try {
String line = null;
while ((line = in.readLine()) != null) {
buff.append(line).append('\n');
}
} catch (IOException ex) {
log.error("Problem getting string from file", ex);
throw ex;
} finally {
if (in != null) in.close();
}
return buff.toString();
}
This method returns the contents of a file as a string that you can then display in your
JSP page.
Hope this helps.
-Steve