0

Hello everyone,
i m designing a web site using jsp and i want to open any files like pdf . doc, etc in the browser without downloading it in the system, files are kept in the location(for eg .g://myfile.doc).
please suggest a feasible solution.

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by priyotosh
0

Is this web site for Intranet (local network often used in medium to large companies, or education institutions) purposes, because g://myfile.doc will not be valid location if on remote server

0

no its not for intranet , we are planning to launch in the internet. Currently it works in the LAN but some of the portion of the viewed file comes corrupted.we are downloading the file in the browser. I m using the following code

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.io.*" %>
<%
  BufferedReader reader = null;
  String line;
  File file = new File("G://GlobalShare.doc");
 
  try {
        response.setContentType("application/msword");
      response.setContentLength((int) file.length());
     // response.setHeader("Content-Disposition","inline; filename=DSC01237.JPG");
      
      reader = new BufferedReader(new FileReader(file));
        while ((line = reader.readLine()) != null) {
          out.print(line);
        }
  }
  catch(FileNotFoundException fileNotFound) {
    out.print("The file does not exist.");
  }
  catch(IOException ioErr) {
    out.print("An error occured during output.");
  }
  finally {
        if (reader != null) {
          reader.close();
        }
  }
%>
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.