View Single Post
  #4 (permalink)  
Old Sep 17th, 2007, 14:00
stevev stevev is offline
New Member
Join Date: Sep 2007
Location: Bristol
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to stevev
Re: Really need help here..urgent!!

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

Last edited by Aso; Yesterday at 11:54. Reason: Sig removed
Reply With Quote