Opening a file in JSP

hi there,
How can i open a file, for example, a text file in JSP? Although i can do this if i place the file in a certain folder, i want to be able to open the file at any directory. Is it possible to do this?

yeep.. since Jsp is essentially a servlet and running on the server you can open anything you want...
in your <%page%> tag you'll have to add import="java.io.*" and then use a FileInputStream or your favorite method of reading the file in and use out.print to display the text of it... kinda similar to:
<%page import="java.io.*" content-type="text/plain"%>
<%
   FileInputStream tis=new FileInputStream("c:\windows\comsetup.log");
   byte[] da=new byte[8192];
   int len=tis.read(da);
   while(len!=-1) {
      out.write(da,0,len);
      out.flush();
      len=tis.read(da);
%>that'd do it.... you can change how the browser "reacts" by changing the content-type at the top...

Similar Messages

  • Open the files in jsp, help!

    i'm trying to call a bean in jsp in order to open a file exists in the same machine as tomcat. but it seems not work properly for no modification occurred to the file after operation on it.
    the sample code is shown below:
    <%
    com.genesys.FileOpr fo=new com.genesys.FileOpr();
    fo.open("...");
    %>
    the routine goes without any exception but either the effect.
    what's the problem?!

    to see something like a download or so you need to set the outputstream encoding type to the correct mime type (jpeg images: "image/jpeg").
    hope you understand it...
    greetings

  • Problem in opening ".pps" file from jsp

    My ".pps" file is on server i want to open this file on client side in microsoft office or inside IE.
    But right now all other types of file are opening except ".pps".
    small part of that code is
    <%
    for(int i=0;i<count1;i++) {
    %>
    <tr align="center">
    <td align="left"><a href="<%= filepath[i %">"><font color="black" size="1" face="Verdana"><%= title[i] %></font></a></td>
    <td align="left"><font color="black" size="1" face="Verdana"><%= filepath[i] %></font></td>
    <td align="left"><font color="black" size="1" face="Verdana"><%= type[i] %></font></td>
    </tr>
    <%
    } %>
    i am retrieving the path of the file in "filepath" variable.
    Anybody plz help me regarding this. Or any different solution.</a>

    I am using plane link to open the file. No streaming is used.OK, then it's certainly a client-side problem. The client simply doesn't recognize the file type and/or it has no application associated with the filetype. No need to worry about it at the server side.
    And i don't know how to set accociation on client side. Windows explorer � Tools � Map options � File types.

  • How to open pdf file in jsp having spaces in file name ?

    hi all,
    i have to open a pdf file in a jsp but some times that pdf file has spaces in the filename
    <a href ="openPdf.jsp?fileName=xyz.pdf">some  pdf file.pdf </a>how to open the pdf file in this case

    more info: java.net.URLEncoder or use response.encodeURL(...) to ensure sessionid is added when cookies are disabled

  • Error in Open Excel Files from JSP..it display Eksponen...

    How to set Excel format in JSP? - Error in Eksponen.
    Hi, i have a problem.
    I am using JSP to select data from database and open it as an Excel file.
    It works perfectly, but the problem is,
    when the data is NUMBER (even though in JSP, i declare it as a String), in the Excel file, when the data is more than 10, the data will change to Eksponen value.
    Should be = 982520000324464
    but in Excel is = 9.8252E+14
    Can anybody help?

    Depending on how you are generating the Excel file there are different solutions.
    If you are generating the Excel file using contentType="application/vnd.ms-excel" and HTML tables, then you can use the following attribute on the cell you wish to format:
    <TD style="vnd.ms-excel.numberformat:#,##0;">24.562234</TD>where the #,##0 corresponds to the format you wish to present the data in.

  • Open Excel file in JSP

    Hi All,
    My action class is returning an String Object on the JSP.
    In JSP I am getting this String object in Request which is coming like
    1,2,3,4,5.................
    now I have to display this in the EXCEL file
    Can we do this..
    Any help is really appriciated
    Thanks in advance.
    Kumar

    I haven't done it using JSP but in a servlet you can set a response header, then return the data as a HTML table and Excel will parse it.
    The servlet code to set the header is
    response.setContentType("application/vnd.ms-excel");

  • Problem in saving modified rtf file in jsp

    hi,
    I have [b]problem in saving modified rtf file in jsp. My scenario is like this:
    I need to open rtf file in jsp and allow user to modify it, after user modifies rtf file in browser, user will press send button. After user pressing send button rtf has to be saved into destination directory(the directory from which its been fetched. I appreciate if any one could send me relevant code for the same.
    thanks
    ram

    1) RTF is not opened in your browser, but in an application that is set to handle the file type (like Word or Wordpad)
    2) from the web you have no control over what that application does
    3) conclusion: what you want is not possible using the web
    Other than that, asking for code without showing that you put some effort into the problem yourself is a sure way of getting flamed. You should know that by now, since you registered more than 2 years ago...

  • Open a file in UNC path from jsp page

    Hi,
    it might be simple but I don't know how i can achieve this,
    I have a UNC path to a remote computer something like this,
    \\ComputerName\SharedFolder\ResourceFileName
    i can open this file from windows by typing the above in Windowes explorer or something like this in browser file://ComputerName/SharedFolder/myfile.txt
    I want a simple jsp page that will have a hyperlink or a button which when clicked should prompt me with a dialog to open/save/cancel the file. it should not open the text fine inside the browser itself. when i click open it should open the file in appropriate viewer(i think this is judged by the mimetypes set on my machine).
    Thanks in Advance.

    khana6454 wrote:
    I want a simple jsp page that will have a hyperlink or a button which when clicked should prompt me with a dialog to open/save/cancel the file. it should not open the text fine inside the browser itself. when i click open it should open the file in appropriate viewer(i think this is judged by the mimetypes set on my machine).You need to set the content disposition to 'attachment' rather than 'inline' (which is default).
    You may find this FileServlet example useful: [http://balusc.blogspot.com/2007/07/fileservlet.html].
    That said, the file needs to be located on the server machine, not on the client machine. If you want to open files from the client machine, rather write a client side application which you can integrate in your webpage, e.g. a signed applet or web start application (jnlp).

  • Problem in opening pdf  or fdf  File in JSP page through firefox in Linux

    Hi,
    In my Webapplication , i have given link to FDF document available in server in a JSP page on click of which the corresponding FDF document should open in a new browser.
    Consider the location of FDF file in my server is
    ServerIP/MS/RDTEST/RDTEST-D-08-10245.fdf
    In my JSP link to FDF file is provided as follows.
    newpath="smb://"+username+":"+password+"@"+serverip+"/MS/RDTEST/RDTEST-D-08-10245.fdf" ;
    <a class ="one1" href="<%=newpath%>" target="dynamic" > RDTEST-D-08-10245 </a>My Requirement is When i click on the link it should open the corresponding fdf file in the browser by following the link provided.
    But it is not working if i try in this way.
    Can anybody suggest how to proceed with this issue.
    Any other ways are there to open fdf file exisitng in server in Firefox in A Linux machine.
    What settings to be made in firefox to support FDF or PDF features.
    What prerequisites needed in Linux to enable FDF or PDF features.
    I have Adobe Acrobat professional 5.0 installed in my Linux machine.
    Thanks in advance.

    Is your problem
    -. That a new browser window doesn't open?
    Solution: [Lookup the 'target' attribute|http://www.w3schools.com/HTML/html_links.asp]
    - That your file content isn't streaming to the browser?
    Solution: Your code assumes the browser understands and supports samba. This isn't always the case (IE for example). And you're providing a direct link to your file with the username and password - security concerns as well as possible portability issues. You'd be better off writing a [file servlet to download your files|http://www.google.com/search?q=file+download+servlet]

  • Jsp page opening pdf file stored in an ORDDOC type column

    Dear All,
    i am building a jsp page that opens a pdf file stored in database. if column type is BLOB, i run the prepareStatement and store in a ResultSet, and then BufferedInputStream(result.getBinaryStream("FILE")). it works. page opens the pdf file.
    but when column type is ORDDOC, i get this error:
    Failure in java.sql.SQLException: Ongeldig kolomtype.: getBinaryStream not implemented for class oracle.jdbc.driver.T4CNamedTypeAccessor
    what more do i do to get a pdf(or txt, msword..) file to jsp page and open it?
    regards
    Jerry

    We are facing this problem with IE6 browser only. In firefox, it opens fine in a browser window. What configuration should we do in IE6?
    Thanks,
    Ananth.

  • How to open a file located at server using JSP

    hi,
    i would like to open a file located at server as it is. I mean to say, if it a MS Word file, i wanna open it in MS Word, if it an Excel file, i wanna open it in Excel. i know the location (path) of the file. Can someone help me please.
    Thanx

    The best way would simply be to HREF it.
    ie<a href="excelfiles/spreadsheet.xls">Open spreadsheet</a>When a user then clicks on that lick in their browser they should be given the option to either download or (if they have the appropriate program, in this case MS Excel, installed) open it.
    This works best if the client is using a version of Internet Explorer (if you're dealing with MS files), but any browser should potentially offer you the option of opening the file.
    Beyond that there's no way to specifically open a program on a client machine (it'd be a bit of a security loophole if you could! - Imagine a JSP page being able to open FDISK...). All you can do is pass the file (via the HREF) and let the client decide what to do with it.

  • Opening Excel  files from a JSP page

    Hi,
    I am not able to open up an Excel file through JSP.
    I am using following code snippet in JSP page
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition","inline; filename=Test.xls");Do i need to do additional settings for rendering Excel from a JSP
    Thanks in advance !!!

    Hi,
    In my application , we have Excel files on the server i.e we are not creating excel sheets.
    I just want to display these static excel files through a jsp.
    I am able to display the excel files by reading them into ByteArrayOutputStream
    <%
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition","attachment; filename=B.xls");
    ServletOutputStream so = response.getOutputStream();
    String filename = "D:\\Test.xls";
    String mimetype = "application/vnd.ms-excel";
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    InputStream in = new BufferedInputStream(new FileInputStream(filename));
    byte bytebuff[] = new byte[500];
    for(int lengthread = 0; (lengthread = in.read(bytebuff)) != -1;){
    output.write(bytebuff, 0, lengthread);
    byte data[] = output.toByteArray();
    response.setContentType(mimetype);
    so.write(data);
    in.close();
    so.close();
    %>But my question is that , do i really need to do all this for rendering excel through a jsp.
    Can't i do it by just setting the content type ?
    Thanks

  • How to open local file in HTML/JSP

    Hi,
    Does anyone know how to open a file outside the war folders?
    I have tried this
    TEST FILE
    but it doesn't work.
    I'm using Jboss4.2
    Thanks,

    You may find this article useful: http://balusc.blogspot.com/2007/07/fileservlet.html

  • How to open .AC3 files in Audition CS5.5

    As the latest Adobe Audition 5.5 does not have the codec/plugin for opening .AC3 files, I need to download and install the latest QuickTime player for the required codec/plugin.
    However, after installing the QuickTime Player, Audition 5.5 seemed to open the .AC3 file I've selected but the whole duration of the AC3 file is blank and has nothing in the waveform. I could not hear anything during the playback.
    The fact is that when the AC3 file is playing through the Windows Media Player 12 with AC3Filter, the file can be heard and has no error.
    Does anyone know the solution to this issue?

    The D7000 was first supported in Camera Raw 6.3.
    http://helpx.adobe.com/creative-suite/kb/camera-raw-plug-supported-cameras.html
    CS5 shipped with Camera Raw 6.0 and is compatible through to Camera Raw 6.7
    http://helpx.adobe.com/x-productkb/global/camera-raw-compatible-applications.html
    Download and install Camera Raw 6.7 and you'll have D7000 Raw support
    Win: http://www.adobe.com/support/downloads/detail.jsp?ftpID=5371
    Mac: http://www.adobe.com/support/downloads/detail.jsp?ftpID=5372

  • Unable to open .chm file from a link in Weblogic 7.0

    Unable to open .chm file from a link in weblogic server. But the same
    jsp code works in Websphere
    Sample Code :
    <!-- < a href="JavaScript:window.navigate('help/manual.CHM')">
    Linked Text</a> -->
    The above link, works well in websphere. help is a folder that
    resides in the server. But when i tried to execute the same in
    Weblogic, some junk characters appeared . so i tried to direct the
    link to Display.jsp and passed the path of the chm file as the
    parameter. I cleared teh out buffer using out.clearBuffer() . i set
    the content type to application/x-msdownload and also set the header
    to content disposition.
    Nothing worked .
    I also tried another way.. That is the following
    I even tried including the mime type
    <mime-mapping>
    <extension>chm</extension>
    <mime-type>application/x-msdownload</mime-type>
    </mime-mapping>
    in the web.xml file. and still it doesnt work
    Nothing Worked . What should i do ? I need immediate help to sort out
    this issue. Can anybody help me
    - Angel

    This could be a Launch Services issue. The following article describes how to manually reset Launch Services — the notes at the bottom of the article also provide information about the side effects of deleting each of the files involved:
    Resetting Launch Services
    If you prefer using a cache cleaning utility instead of following the manual procedure described in the previous article, take a look at this other article for general troubleshooting and cache-cleaning procedures. Actually, you should also verify/repair the startup disk (not just permissions), as described there:
    Resolving Disk, Permission, and Cache Corruption
    The most appropriate utility for this particular problem probably is Tiger Cache Cleaner, but you may also want to consider other utilities, such as OnyX, or Cache Out X, which are free. Whatever utility you choose, be sure to read this first:
    Side effects of System cache cleaning
    As an example, this is how you should proceed with OnyX:
    1. Quit all applications.
    2. Launch OnyX and enter your administrator password.
    3. Go to Maintenance > Reset and check LaunchServices database.
    4. Un-check any other pre-checked options.
    5. Click the Execute button.
    6. Restart the computer.
    BTW, if you’re running Mac OS X 10.4 (Tiger), as your profile indicates, it would have been more appropriate to discuss this in the Mail & Address Book - Tiger forum. If the discussion applies to both Mail 1.x and Mail 2.x, it doesn’t really matter, but it’s difficult to know that in advance.

Maybe you are looking for