Open a Local file from JSP

Hi All,
I want to access a local file from a JSP. On click of the link the local file should open. The location of the local file is
O:/VWS00000000000000000001/REPORT_FRAGMENTS/Title1.doc
and the hyper link on the JSP shows
file:///O:/VWS00000000000000000001/REPORT_FRAGMENTS/Title1.doc
somehow the file does not open from the JSP page but it opens from the browser if I type
'file:///O:/VWS00000000000000000001/REPORT_FRAGMENTS/Title1.doc' in the address bar.
Can anybody please help.
regards,
Shardul.

if you'd like to show the real path to the user, use simply an ftp server !
however, if you prefer a secure solution, so use a servlet:
example:
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SendWord extends HttpServlet {
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    //get the 'file' parameter
    String fileName = (String) request.getParameter("file");
    if (fileName == null || fileName.equals(""))
      throw new ServletException(
          "Invalid or non-existent file parameter in SendWord servlet.");
    // add the .doc suffix if it doesn't already exist
    if (fileName.indexOf(".doc") == -1)
      fileName = fileName + ".doc";
    String wordDir = getServletContext().getInitParameter("word-dir");
    if (wordDir == null || wordDir.equals(""))
      throw new ServletException(
          "Invalid or non-existent wordDir context-param.");
    ServletOutputStream stream = null;
    BufferedInputStream buf = null;
    try {
      stream = response.getOutputStream();
      File doc = new File(wordDir + "/" + fileName);
      response.setContentType("application/msword");
      response.addHeader("Content-Disposition", "attachment; filename="
          + fileName);
      response.setContentLength((int) doc.length());
      FileInputStream input = new FileInputStream(doc);
      buf = new BufferedInputStream(input);
      int readBytes = 0;
      while ((readBytes = buf.read()) != -1)
        stream.write(readBytes);
    } catch (IOException ioe) {
      throw new ServletException(ioe.getMessage());
    } finally {
      if (stream != null)
        stream.close();
      if (buf != null)
        buf.close();
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    doGet(request, response);
}hope that helps

Similar Messages

  • Open a local file from a web Service

    Hello!
    Likely this is a trivial question, but I need to open a local file from a Web Service and i don't know how to get the file path. I mean that I have a WS source code placed in a proper package (my.ws.package) with an additional configuration XML file placed in the same directory. I need to read it, but if I use merely
    File conf = new File("Conf.xml");it can't find it. I've tryed with:
    MyWS.class.getClass().getProtectionDomain().getCodeSource().getLocation().getPath()in order to get the file path, but a
    java.security.AccessControlException access denied (java.lang.RuntimePermission getProtectionDomain)arises...
    I don't know...
    Suggestions?
    Thanks.
    Anhur

    Hello!
    Likely this is a trivial question, but I need to open a local file from a Web Service and i don't know how to get the file path. I mean that I have a WS source code placed in a proper package (my.ws.package) with an additional configuration XML file placed in the same directory. I need to read it, but if I use merely
    File conf = new File("Conf.xml");it can't find it. I've tryed with:
    MyWS.class.getClass().getProtectionDomain().getCodeSource().getLocation().getPath()in order to get the file path, but a
    java.security.AccessControlException access denied (java.lang.RuntimePermission getProtectionDomain)arises...
    I don't know...
    Suggestions?
    Thanks.
    Anhur

  • How to open a local file from javascript in a jsp-page

    Hi
    I have created an iview from a PAR file. In the par file I have a jsp-page with some javascript code. From the javascript coe I want to open a new window with an Excel file.
    I have tried window.open("c:
    test.xls", "test_window"), but it doesn't seem to work. I have created a small HTML page locally with the same command and there a new window opens with the Excel file.
    If I change the local file path with an URL it also works.
    Any idea how to open a local file ?
    Thanks
    /Jakob

    Jacob,
    I'm not 100% (but 99,9%) and it has to do with security ristrictions of the browser not allowing to have local workstation interation from the web. This is ofcourse very dangerous if the browser would allow it... So therfore it is blocked. What if somone would point to a file/executable that formats your drive so for that reason it is not allowed to have web interaction with a local file. Only with Java Applets this is possible but still with many limitations, and what I remember Google Gears and Adobe Air do have some limited web 2 local file interaction... So best and most simple solution you are left with is pointing to a url instead of a file on a c:\ drive.
    PS The reason why it works when you start the html from your local PC has todo with the fact that the browser detects that the html is not running in the web at that moment therefor allowing the access.
    Cheers,
    Benjamin Houttuin

  • How to print a local file from jsp

    Hi,
    I want to print a local file(eg. .doc,.pdf) from a jsp.
    Please help me with any answer or any example code
    Thanks in advance
    Regards,
    Sanjeev

    Try this:
    index1.jsp:
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <Link rel='alternate' media='print' href=null>
    <script Language=JavaScript>
    function setPrintPage(prnThis){
    prnDoc = document.getElementsByTagName('Link');
    prnDoc[0].setAttribute('href', prnThis);
    window.print();
    </script>
    </head>
    <body >
    <a href="#" onclick="setPrintPage('index.jsp');"> Click to Print </a>
    </html>This will print index.jsp without opening it in browser. Hope this helps!

  • Open an excel file from jsp

    Hi,
    I want to open an excel file on click of a link in the jsp.
    At present iam using href which i feel is not correct as it is not able to recognize the excel format and paints the entire screen with special characters.Can anyone please help me out.
    Thanks,

    In your server, there should be some way to tell the server the mime type of a file based on the file's extension. So, you tell the server for every file with the extension of .xls, it should use the mime type of application/vnd.ms-excel. Then, when the link is clicked on, the browser will receive the mime-type message of application/vnd.ms-excel and will open Excel to work with the file.
    Hope this helps,
    Ron

  • Get local file in jsp

    Hi,
    I am trying to access the local file which is on local system from the JSP page.I know that it is not possible to access local file from jsp page wheather it is not present on the server.Just i need a conformation that it is possible or not.If it is possible then how can i access it or it is not possible then there is another way to access that local file from jsp page.Plz help its Urgent.

    You have 2 possible solutions.
    1) Use a File Upload form. This is an HTML form which the user browses to the file, selects it, then submits. The local file is then copied to the server and is available as a server side resource for servlets and JSPs. If you google File Upload Servlet you will get examples. If you choose this route you should look into the Apache Commons FileUpload project.
    2) Use a client side application like a signed Applet or Web Start. The signed Applet will be able to access the file (perhaps with user interaction) and can use internal methods to transfer data from it to the surrounding HTML page or back to the server. It does need to be signed, though, because Applets are typically in a sandbox which prevents them from touching the file system. Web Start does not need a digital signature but does need use acknowledgment to run.

  • I cannot view PDF in Firefox at the first time but once I manually open the PDF file from my local computer, I can view other PDF files via Firefox webbrowser

    I install Adobe Acrobat 9 in my laptop which runs on windows 7. I use Firefox 3.6.8 and have the problem with the PDF file. The problem is I cannot open the PDF file in Firefox web browser at the first time I launch firefox. It shows a warning box without any message. Only OK button is shown so I can close it. However, if I manage to open the PDF file from my local computer by just using adobe acrobat itself then the PDF can be opened in the Firefox web browser. I followed the instruction on the mozilla help but nothing works for me. The problem still exists. I wonder if anyone have the same problem like me and know how to solve this. Thank you so much

    Hi there!
    I cannot help you, but I think we have a common problem: We got a system here running Vista SP1 with Acrobat 9 standard on it. When we open a pdf file it works normally, but when we open another pdf file, we see the first one in that second window.
    Think that missing option to watch several files within a single window-thing messed up more than meets the eye ... but as we just purchased the 15 licenses, we have to use version 9.
    I didn't find any clues on this problem, but I will post any new hints I get.

  • Opening a rft file from the jsp

    hi all,
    i want to open an rtf file from the jsp. i need to call a rtf file present in some location and convert the file to bytes thereby writing these bytes to output stream and so.. can anyone suggest me here.
    it should be something like this :
    String sFileName = "/kli/terms&conditions/TermsandConditionsLitigation.rtf";
                  File nameOfFile = new File(sFileName);
                  FileOutputStream fout = new FileOutputStream(nameOfFile);
                  response.setContentType("application/rtf");
                  response.setHeader("Content-disposition","attachment;filename=\"" +sFileName+ "\"");
                  ServletOutputStream outs = response.getOutputStream();
                  outs.write(fout);
                  outs.flush();
                  outs.close();satish.
    Message was edited by:
    bobz
    Message was edited by:
    bobz

    Yes, unlike earlier IE versions, IE10 has only one executable, but it can run in 32-bit or 64-bit mode.
    Some details: http://www.sevenforums.com/tutorials/280434-internet-explorer-10-enable-32-bit-64-bit-ie10 -windows-7-a.html

  • Saving a File in local DISK from JSP

    Hi Techies,
    I had createe an xml file from jsp, I want to store it in localdisk like when we download some files from internet it will ask at what location u want to store.
    i.e the end user can give the location at which this xml file has to be stored.
    Looking forward for u r solutions??
    regards,
    Krish

    No ideas??

  • Why can't Bridge open my raw files from Canon PowerShot 120-S? Using PS/5

    Why can't Bridge open my raw files from my new Canon Power Shot 120-S camera? I'm using PS-5 and had no problems with other Canon cameras. I downloaded Adobe Camera Raw 8 but this has not resolved the problem.
    Jack

    1. you need cr 8.3+ for the Canon PowerShot S120
    2. ps cs5 can only update to cr 6.7
    free solution: use the dng converter: http://www.adobe.com/support/downloads/detail.jsp?ftpID=5694
    integrated solution: upgrade to ps cc.  here are the options (but especially note the photographer plan for 9.99/mo) - http://www.adobe.com/products/photoshop/buying-guide.html

  • Cannot open nikon raw files from my 3200 in elements 8

    i cannot open nikon raw files from my 3200 in elements 8

    http://helpx.adobe.com/creative-suite/kb/camera-raw-plug-supported-cameras.html
    You would need PSE11 since the 3200 requires ACR version 7.1
    Only PSE11 can have 7.1, so to be able to use your raw files with PSE9 you should download the free Adobe DNGconverter which can batch convert a whole folder of raw files into the Adobe raw DNG format which your PSE8 can open.
    http://helpx.adobe.com/x-productkb/multi/troubleshoot-camera-raw-photoshop-photoshop.html
    http://www.adobe.com/support/downloads/detail.jsp?ftpID=5486
    http://www.adobe.com/support/downloads/detail.jsp?ftpID=5518

  • I have just bought a Panasonic Lumix compact camera. Aperture and Preview can't open the RAW files from this camera. Panasonic recommend downloading 'SYLKPIX Developer Studio SE' to save RAW file formats.How can Aperture and Preview read the files?

    I have just bought a Panasonic Lumix compact camera. Aperture and Preview can't open the RAW files from this camera. Panasonic recommend downloading 'SYLKPIX Developer Studio SE' to save RAW file formats.How can Aperture and Preview read the files?

    Either use 'SYLKPIX Developer Studio SE' to develope the RAW files and to save them in another lossless format like TIFF, or try if Adobe's free DNG Coverter can convert your Lumix RAW files to dng. Then import the dngs. This way, your files will still be RAW files.  This works (most times) for my Lumix FZ28.
    Adobe DNG Converter 8.3  http://www.adobe.com/support/downloads/detail.jsp?ftpID=5695

  • When i open an mp3 file from a source other than apple, does itunes create it's own file and can I then delete the original mp3?

    when I open a music file from a source other than apple, does itunes create it's own file and can I then delete the original mp3?

    If you use iTunes' default settings then when you add a file to iTunes it places a copy of the file in the iTunes media folder and it leaves the original in place.  The exception is when you drag it to the Automatically Add To iTunes folder.
    It does not convert the file.  You can delete the original if you wish.

  • Unable to open large PDF file from the Attachment list.

    Hi Gurus,
    Users had attached 10 PDF file in the work order attachment list and his supervisor is trying to open the PDF file from the work order attachment list and he is able to open 9 PDF files without any issue, but 1 PDF file is giving the error message as "Database error for <GET DATA FROM KPRO>" and then select ok, we are getting the below message.
    Window cannot find u201CC/Documents and Settings/b2m/SaoworkDir/5015851 Vendor data sheets B&P 2010 SDown XXX .PDFu2019. Make sure you typed the name correctly, and then try again. To search for a file, click the start button, and then click serch.
    Looks like this particular file is not transferring to the SAP work directory.
    Could you please check and suggest us as to how to fix it.
    Thanks & Regards,
    Srivas

    Hi,
    Thanks for your reply.
    We verified  your OSS notes it's not relevant to us Because our issue is while opening the PDF aatchement it is not transferring to my SAP Work Directory because of that reason we are getting the KPRO error. When I'm opening the other PDF files it's transferring to my SAP Work Directory and it's automatically open without any issue.
    Please check and suggest.
    Thanks,
    Srivas

  • How to open an InDesign file from CMIS repository?

    We are using CS SDK 2.0 , looking to use CMIS to keep versionning of .indd file. The uss case as following:
    form our de4veloped InDesign pluging, user click a button
    the button will open a .indd file from cmis repository
    plugin check-out the file, open it within InDesign IDE
    user make changes
    user make save
    the plugin export a pdf and swf files from the current document, if the files exists it will update, aslo on CMIS repo to keep also versions of exported pdf and swf, if files not exist in first time .. it will create
    when user clos the document , it will check it in.
    the problem there is no sufficent sample code for, even was thinking to use Adobe Drive, but there is no Adobe Drive SDK for Flex.
    i used to fuse the sdk, but
    private function getFileByPath(sPath:String):Fileable {
    appStatus = ">> get File By Path";
    message = "";
    viewEnabled = false;
    var request:GetObjectByPathRequest = new GetObjectByPathRequest(session);
    var oFileable:Fileable;
    request.path = sPath;
    request.execute(onSuccess, onError);
    function onSuccess (event:GetObjectByPathResponse) : void {
    oFileable = event.object;
    //var oDoc2:Document = new Document(event.object);
    doc = event.object as Document ;
    //children = new ArrayCollection(vectorToArray(event.target));
    appStatus = ">> getFileByPath : Success";
    viewEnabled = true;
    return oFileable;
    private function checkOutFile(oFile:Document):Document{
    appStatus = ">> Check Out File";
    message = "";
    viewEnabled = false;
    var request:CheckoutRequest = new CheckoutRequest(session);
    request.object = doc;
    var oDocument:Document;
    request.execute(onSuccess, onError);
    function onSuccess (event:CheckoutResponse) : void {
    oDocument = event.object ;
    appStatus = ">> Check Out File : Success";
    viewEnabled = true;
    return oDocument;
    private function openTestFile():void {
                                            appStatus = "Open Test File";
                                            message = "";
                                            viewEnabled = false;
                                            var oFile:Fileable  = getFileByPath("/Collaboration/test.indd");
                                            //var oDoc2:Document = new Document(oFile);
                                            var oDoc:Document  = checkOutFile(doc);
    i do not know what method in the CS SDK to open document fom active window and  how to map CMIS Document to com.adobe.indesign Document ?

    Dear Seoras
    i fixed the to return the cmis path:
    public function resolveRemotePath(file:File):String
                                  if (file.nativePath.indexOf(LOCAL_FILE_CACHE.nativePath) != 0)
                                            return null;
                                  var remoptePath:String =file.nativePath.substr(LOCAL_FILE_CACHE.nativePath.length);
                                  trace("resolveRemotePath [11] : "+ remoptePath);
                                  if(File.separator!="/") {
                                            //var pattern:RegExp = /(\/)/g;
                                            var pattern:RegExp = /(\\)/g;
                                            remoptePath =  remoptePath.replace(pattern ,"/");
                                            trace("resolveRemotePath [22] : "+ remoptePath);
                                  return remoptePath;
    i have another issue, why everytime update the generated pdf it creates new pdf file with same name in the cmis repo .. does the pdf is not updatable over the cmis service ???
    Regards

Maybe you are looking for

  • How to populate a page with images in across/down direction?

    Hi, Does anyone know how to populate a page with images in across and down direction (for example 6 X 6 )? It seems that I cannot use data table because records are only running downward and each row can have one record. Any suggestion would be appre

  • How to display success message when data is changed in the custom tab in MM

    Hi, I have added a new custom data tab in the MM01/MM02/MM03 transactions. Whenever I do changes to fields in the custom tab in MM02 transaction, and no changes in the standard tabs, I will get a message stating "No Changes Made". But if I do changes

  • Toolbar Button not Appearing in Plugin

    The following code is not producing a button in the file toolbar in Acrobat 8 Professional, despite being called from PluginInit: bool AddToolbarItems() AVToolBar toolBar = AVAppGetToolBar(); AVToolButton endToolsGroupButton; //No tool bar? if (!tool

  • Css not rendering correctly

    I am getting a discrepancy on one class in firefox vs. IE. Any suggestions are welcome! I would like the "fetch" div to have the text box and arrow aligned evenly, then a padding on the bottom of 5 pixels. In both browsers it is showing the submit bu

  • HT204291 I

    I have an iPad 4 and an iPhone 5. I can't connect either to my Apple TV. I have been able to connect them to a friends but when I use my Apple TV I don't get an airplay icon?? I have airplay open on the TV and both are on the same wifi network