How to display file content in browser using servlet..? urgent!!!

hello,
i am building a application for which when a user logs in he will we redirected to page where he will have one link ,with this link a file is associated.
when user press that link he should be able to see that particular file in internet browser....
now can anybody give me a code sample of how to display a file in browser....
please reply me as soon as possible...

thanks for your reply....
but i don't want this....
i want to read a file from disk into stream or buffer and from that again reading and printing in browser.....
a servlet should be built for this....
i wrote this but its not working
========================================================
public class FilePrinting extends HttpServlet
     public void doPost(HttpServletRequest req,HttpServletResponse res)
          throws IOException,ServletException
          ServletOutputStream out=res.getOutputStream();
          res.setContentType("text/html");
          String fileURL="/mydomainWebApp/Test.htm";
          res.setHeader("Content-disposition","attachment; filename=" +="Test.htm" );
          BufferedInputStream bis=null;
          BufferedOutputStream bos=null;
          try
               URL url = new URL( fileURL );
               bis=new BufferedInputStream(url.openStream());
               bos = new BufferedOutputStream(out);
               byte[] buff = new byte[2048];
               int bytesRead;
               // Simple read/write loop.
               while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
               bos.write(buff, 0, bytesRead);
          }catch(final MalformedURLException e)
               System.out.println ( "MalformedURLException." );
               throw e;
          }catch(final IOException e)
               System.out.println ( "IOException." );
               throw e;
          }finally
               if (bis != null)
                    bis.close();
               if (bos != null)
                    bos.close();
=======================================================================
please send me sample code if anyone have../...

Similar Messages

  • How to display file contents on a web page

    On unix platform I have created a class that can read the contents of a file and display them to the standard output. But now i want to display these file contents on a web page through jsp. On JSP code I have imported this class and want to assign a record from a file and write it to the screen using html. I think the class needs to be modified in order to return the string record read from a file so that im able to access it from a jsp and assign it to a variable the I can display it on the screen. Can someone help me with these code?

    Actually, you mean Linksys.  BIG difference there.
    Linksys Business Series was accumulated into Cisco Small Business, since it was purpose built for small business, not residential/consumer grade.
    The new PVC2300 actually are Cisco branded on the case.
    The collateral you seek is protected by the business unit that supplies it, since it was placed on a portal that only Cisco registered partners can access.
    As I wrote, I already checked with the BU and they told me thats where it lives and not to hand it out.  I cannot override that. 
    I am not sure there are any secrets in there, but I dont make the rules, sorry.
    Do you want to be a Cisco Partner?   Sign up and gain access to everything you need to sell Cisco successfully to end customers?  If you tell me your geography (city/state/zip, I will have an ICAM call you and help recruit you.....
    Steve D
    Systems Engineer
    U.S. Partner Sales team
    RTP, N.C.

  • How to save file content in BLOB using ODI?

    We have unix server where the files are stored in a particular directory.
    I have to create one table in Oracle db which will have 2columns.
    One column will have filename & in another column i need to store file content(whatever that file has) which should be a BLOB type.
    There is no restriction on file type,it could be .txt,.xls,.jpg.
    Need help
    Edited by: user11090018 on Jun 9, 2010 4:24 AM
    Edited by: user11090018 on Jun 10, 2010 10:22 PM

    If you can give a detail explanation about your requirement then we may try to come up with a solution .....

  • How to display link content on the the same sharepoint page on click event

    "How to display link content on the the same sharepoint page on click event"
    Detail:
    we are using a document library where all html files are stored/uploaded.  we would like to display/open the html file on the same sharepoint page where all the files are listed.
    Thanks.

    Use jQuery and set the target to self to the anchor tag
    Regards,
    Sairam Avacorp Technologies

  • How to display file extensions

    Hi,
    I'm trying to get our Sharepoint 2013 server to show file extensions again and I've had no luck so far. I've been able to add an extra name column that shows the file extension (like ), but that name is not clickable anymore so I've ended up with one name
    that's a link and the same name next to it. This doesn't look good, especially when the users pick overly long file names.
    This (http://social.technet.microsoft.com/wiki/contents/articles/11161.how-to-display-file-extensions-in-a-sharepoint-document-library.aspx) seems to apply to Sharepoint 2007 only. I'm not sure which onet.xml file they mean and the default file has several
    occurences of "Name=”Created_x0020_Date”", or how adding
    Name=”File_x0020_Type”/> without an extra opening bracket would work.
    I've also found and tried this solution: http://social.technet.microsoft.com/Forums/sharepoint/en-US/59c15eee-9116-4aa1-8d16-32cd361c9a2f/show-file-extensions-in-document-library?forum=sharepointcustomizationprevious
    >>3. Edit the WebPartPages:XsltListViewWebPart so that the link contains the extension.
    >>a. Open SharePoint Designer and click on the desired document library.
    >>b. Open the View you want to change, which in most cases is "All Documents".
    >>c. Find the line that looks like this:
    >><xsl:value-of select="$thisNode/@FileLeafRef.Name" />
    >>d. Edit the line to look like this:  (the xsl:if tests to see if the suffix is not blank and then displays a '.' and the suffix)
    >><xsl:value-of select="$thisNode/@FileLeafRef.Name" /><xsl:if test="$thisNode/@FileLeafRef.Suffix!=''">.<xsl:value-of select="$thisNode/@FileLeafRef.Suffix" /></xsl:if>
    This doesn't seem to work with Sharepoint 2013 because the line <xsl:value-of select="$thisNode/@FileLeafRef.Name" /> doesn't seem to exist. Are there any other suggestions on how to get the file extensions to show?
    Thank you.

    Hi
    use these functions
    RIGHT (Text, Number)
    Return X characters from the right
    RIGHT(“The Quick Brown Fox”, 5)
    n
    SEARCH(Text1, Text2, Num)
    Returns the index of Text1 within Text2,starting the search at index Number
    Formula should be
    right([Name-column],search[".",[Name-column],1))
    More info regarding calculated columns
    http://junestime.wordpress.com/2013/02/12/sharepoint-calculated-column-formulas/
    Romeo Donca, Orange Romania (MCSE, MCITP, CCNA) Please Mark As Answer if my post solves your problem or Vote As Helpful if the post has been helpful for you.

  • Idoc-xi-file scenario.  how to display file in html format

    I am not sure whether this is a valid question.........but want to confirm as it was asked by somebody
    In idoc-xi-file scenario.......  how to display file in html format ??
    Thanks in advance
    Kumar

    Hi Vijayakumar,
    Thanks for your reply !! You mean to say I got to use XSLT mapping and also .htm and .html extension together to produce the html file ?? or it is sufficient to use any one of them to produce the html file ??
    Regards
    Kumar

  • How to display the content of a BLOB column in a ADF/BC pages ?

    How to display the content of a BLOB column in a ADF/BC pages ?
    There is some image in database table blog column. And we want to display image on the screeen.
    There is some example about upload and dowload blog columns.
    (steve not yet document example page etc...)
    But We want to display blog picture in a image component...
    is there any basic way to do it ?
    Thanks a lot...

    Ali,
    You could just download the sample app... but... here is the servlet code from the demo (look at it just for technique - you'll obviously have to change it for your needs)...
    John
    package oracle.fodemo.storefront.servlet;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import oracle.jbo.ApplicationModule;
    import oracle.jbo.Key;
    import oracle.jbo.Row;
    import oracle.jbo.ViewObject;
    import oracle.jbo.client.Configuration;
    import oracle.jbo.domain.BlobDomain;
    import oracle.jbo.domain.DBSequence;
    import oracle.jbo.domain.Number;
    import oracle.jbo.server.ViewObjectImpl;
    public class ImageServlet
      extends HttpServlet
      private static final String CONTENT_TYPE =
        "image/jpg; charset=windows-1252";
      public void init(ServletConfig config)
        throws ServletException
        super.init(config);
      public void doGet(HttpServletRequest request,
                        HttpServletResponse response)
        throws ServletException, IOException
        response.setContentType(CONTENT_TYPE);
        response.setContentType(CONTENT_TYPE);
        String detailProductId = request.getParameter("detail");
        String thumbnailProductId = request.getParameter("thumbnail");
        boolean thumbnail = true;
        String productId = null;
        OutputStream os = response.getOutputStream();
        String amDef = "oracle.fodemo.storefront.store.service.StoreServiceAM";
        String config = "StoreServiceAMLocal";
        ApplicationModule am =
          Configuration.createRootApplicationModule(amDef, config);
        ViewObjectImpl vo =
          (ViewObjectImpl) am.findViewObject("ProductImages"); // get view object (the same as used in the table)
        if (detailProductId != null)
          productId = detailProductId;
          thumbnail = false;
        else
          productId = thumbnailProductId;
        vo.defineNamedWhereClauseParam("paramThumbnail", null, null);
        vo.defineNamedWhereClauseParam("paramProductId", null, null);
        vo.setWhereClause("DEFAULT_VIEW_FLAG = :paramThumbnail AND PRODUCT_ID = :paramProductId");
        vo.setNamedWhereClauseParam("paramThumbnail", (thumbnail? "Y": "N"));
        vo.setNamedWhereClauseParam("paramProductId", productId);
        vo.executeQuery();
        Row product = vo.first();
        BlobDomain image = (BlobDomain) product.getAttribute("Image");
        InputStream is = image.getInputStream();
        // copy blob to output
        byte[] buffer = new byte[10 * 1024];
        int nread;
        while ((nread = is.read(buffer)) != -1)
          os.write(buffer, 0, nread);
        os.close();
        vo.setWhereClause(null);
        vo.removeNamedWhereClauseParam("paramProductId");
        vo.removeNamedWhereClauseParam("paramThumbnail");
        Configuration.releaseRootApplicationModule(am, false);
    }

  • How to display the contents of the database values which are retrived.

    how to display the contents of the database values which are retrived in servlets and i am able to display the contents in the servlets and if forward to jsp using requestdespatcher,the values are to be shown in jsp one below the other.please suggest me in these........the servlet code is as shown
    while(rs.next()){
                        buffer.append(rs.getString(1));
                        buffer.append(rs.getString(2));
                        buffer.append(rs.getString(3));
                        buffer.append(rs.getString(4));
                        buffer.append(rs.getString(5));
                        buffer.append(rs.getString(6));
                        buffer.append(rs.getString(7));
                        buffer.append(rs.getString(8));
                        buffer.append(rs.getString(9));
                        buffer.append(rs.getString(10));
                        request.setAttribute("result1",buffer);
                        RequestDispatcher rq=request.getRequestDispatcher("/results.jsp");
                        rq.forward(request,response);
    in jsp iam using the getAttribute to retrieve the values as shown
    <% StringBuffer sb=(StringBuffer)request.getAttribute("result1"); %>
    <%= sb %>
    but getting the results in the stretch,i need to display the result one below the other.

    if you load it all into the buffer that is going to be very difficult. I would suggest loading it into some sort of collection. I like using an ArrayList.
    Then pass the arraylist.
    you will then on the jsp iterate through the arrayList using what every you want.. el, logic tags, scriplets.
    so something like
    ArrayList arrayList = new ArrayList();
    while(rs.next()){
    arrayList.append(rs.getString(1));
    //or possibly an arrayList of String arrays
    //maybe using nested for loops.  Inner for loop adds result to string[] then //outer adds string[] to arrayList.
    //can be done any number of ways based on your expected result set.

  • Does anyone know how to display (in LabVIEW) the memory use during execution of an image and data acquisition VI to predict when it is time to cease the acquisition to prevent the program crashing?

    Does anyone know how to display (in LabVIEW) the memory use during execution of an image and data acquisition VI to predict when it is time to cease the acquisition to prevent the program crashing?
    I am acquiring images and data to a buffer on the edge of the while loop, and am finding that the crashing of the program is unpredictable, but almost always due to a memory saturation when the buffers gets too big.
    I have attached the VI.
    Thanks for the help
    Attachments:
    new_control_and_acquisition_program.vi ‏946 KB

    Take a look at this document that discusses how to monitor IMAQ memory usage:
    http://digital.ni.com/public.nsf/websearch/8C6E405861C60DE786256DB400755957
    Hope this helps -
    Julie

  • How to display the content of a region on a different page

    Hello,
    Does anyone knows how to display the content of a region on an other page. I try to make page that displays content that resides somewhere else in my portal, so I can give a summarization of some hot topics. I really want to display the whole content of some regions (not a display with custom search).
    Thanks a lot,
    Hans

    Set that page as portlet, include it in a region in another page and in the edit defaults decide which regions you want to display.
    Mere.

  • Does anyone know how to display (in LabVIEW) the memory use during execution of an image and data acquisitio​n VI to predict when it is time to cease the acquisitio​n to prevent the program crashing?

    Does anyone know how to display (in LabVIEW) the memory use during execution of an image and data acquisition VI to predict when it is time to cease the acquisition to prevent the program crashing?
    I am acquiring images and data to a buffer on the edge of the while loop, and am finding that the crashing of the program is unpredictable, but almost always due to a memory saturation when the buffers gets too big.
    I have attached the VI.
    Thanks for the help
    Attachments:
    new_control_and_acquisition_program.vi ‏946 KB

    got these vi's off ni site a while ago - see if they help
    Attachments:
    Memory_Monitor.zip ‏132 KB

  • How to display multiple tables from database using netbeans swing gui

    plz reply asap on how to display multiple tables from database using netbeans swing gui into the same project

    Layered Pane with JTables or you can easily to it with a little scripting and HTML.
    plzzzzzzzzzzzzzzzzz, do not use SMS speak when posting.

  • How file dowloading concept works using servlets.

    How file dowloading concept works using servlets.
    We will get window when downloading something from site
    if we close that window downloading stops.
    how this process works if we use servlets .
    Or what are the general concepts for downloading a file

    How file dowloading concept works using servlets.You send a request and get a reply stream. Where the servlet gets the data from is totally irrelevant.
    We will get window when downloading something from
    site
    if we close that window downloading stops.
    how this process works if we use servlets .If you close that window, downloading stops.
    Or what are the general concepts for downloading a fileSend a request, get a reply stream.

  • How do I get the Tomcat port using Servlet.

    I am running Apache + Tomcat. All request are going though Apache. How do I get the Tomcat port using Servlet.

    See:
    ServletRequest.getServerPort()This will give the port upon which the request was recieved . . .which I blelieve is what you are looking for.

  • How to display RTF File in Browser Using Servlets/JSPs

    Hi All,
    I have some RTF Files, which contains some data.
    The data needs to be displayed in the frame of jsp page .
    How i can display the RTF File Content using either servlets/jsps
    Can any body have idea on this.
    Help me out on this.
    With Regards
    Hari

    If you only need to display it, consider your HttpServletRequest just as byte stream. :) Just read from ServletInputStream and write it back into ServletOutputStream of HttpServletResponse.
    If you want to process incoming XML, please give some details first, what exactly you want to do. :)

Maybe you are looking for

  • Motion crashes when attempting to start a project

    I've got a mac pro in which motion crashes every time the user tries to open a project, be it a new blank one or an old project. The mac itself is a single CPU quad 2.8 with 6 gig ddr3 and an ati 5770 I've already tried uninstalling and re-installing

  • Links to Word template from Reader X

    I have setup pdf document with links to Microsoft Word templates. They were working correctly in Reader 9 and they are working correctly when opened from Acrobat X Professional but when I open pdf file in Reader X the do not work. In Acrobat Pro clic

  • Mpc in fpga

    sir, myself sajingopi doing masters in automation. I am trying to implement Model predictive control in fpga and the platform that i am using is labview. First stage of the project was over in which i tried to implement MPC in labview and got the req

  • Dynamic datagrid

    Hey all. I have a datagrid that has it's columns generated dynamically based on whatever columns are in the database. I have no problems retrieving the columns and dynamically creating my datagrid with those columns. My problem arises not with genera

  • Facebook For BlackBerry Smartphone​s

    This is just a general enquirery that maybe only somebody from RIM may be able to answer how come other OS's E.G iPhone and Android have the function to locate the town you're in and add it to a status for example when you put a status on instead of