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. :)

Similar Messages

  • How to display XML file in browser using Servlets?

    Hi My XML file is like this:
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:purchase_order_MT xmlns:ns0="http://filetohttp.com">
    <ORDER_HEADER_IN>
    <purchase_date/>
    <purchase_group/>
    <purchase_org/>
    </ORDER_HEADER_IN>
    <vendor/>
    <ORDER_ITEMS_IN>
    <item>
    <storage_location/>
    <plant/>
    <quantity/>
    <material/>
    </item>
    </ORDER_ITEMS_IN>
    <ORDER_SCHEDULES_IN>
    <item>
    <delivery_date/>
    </item>
    </ORDER_SCHEDULES_IN>
    </ns0:purchase_order_MT>
    My Servlet receives this XML file and it should display the above XML as it is, How to do that?
    Please help me I have posted same question in many forums but i got no proper reply.
    Thanks a lot

    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. :)

  • How to display RTF file and .doc file in JTextPane

    How to display RTF file and .doc file in JTextPane??

    Duplicate post
    http://forum.java.sun.com/thread.jsp?forum=57&thread=567029&tstart=0&trange=30

  • How to upload a file into server using j2ee jsp and servlet with bean?

    How to upload a file into server using j2ee jsp and servlet with bean? Please give me the reference or url about how to do that. If related to struts is more suitable.
    Anyone help me please!

    u don't need j2ee and struts to do file uploading. An example is as such
    in JSP. u use the <input> file tag like
    <input type="file"....>You need a bean to capture the file contents like
    class FileUploadObj {
        private FormFile srcFile;
        private byte[] fileContent;
        // all the getter and setter methods
    }Then in the servlet, you process the file for uploading
        * The following loads the uploaded binary data into a byte Array.
        FileUploadObj form = new FileUploadObj();
        byte[] byteArr = null;
        if (form.signFile != null) {
            int filesize = form.srcFile.getFileSize();
            byteArr = new byte[filesize];
            ByteArrayInputStream bytein = new ByteArrayInputStream (form.srcFile.getFileData());
            bytein.read(byteArr);
            bytein.close();
            form.setFileContent(byteArr);
        // Write file content using Writer class into the destination file in the server.
        ...

  • Displaying *.pdf file on browser with servlet

    hi all
    this RAMESH,struggling to display a pdf file on browser from a remote mechine
    earlier i tried with servlet
    response.setContentenType("application/pdf")
    out.println();
    by this i am getting only some data as below
    endobj
    4 0 obj
    <<
    /ProcSet [ /PDF /Text /ImageB ]
    /Font << /Fo0 21 0 R /Fo12 24 0 R /Fo13 27 0 R /Fo16 30 0 R /Fo18 33 0 R /Fo19 36 0 R >>
    >>
    endobj
    For this purpose i have gone thru www.lowagie.com
    and gone thru all examples but i am not getting how to display on browser or at least awt frame
    please requesting all for suggest me some way
    tanks all
    -Ramesh

    are you trying to
    a) create a PDF dynamically
    b) send an existing PDF

  • How to open pdf files in browser using flex

    hi,
    my project is having a Document explorer wchich contains pdf
    files,iwant to open it in the browser.can any one tell me how to
    open pdf documents using flex programming(i tried with different
    thing like swf's but my client wants only pdf formatt).

    Another option is by calling a JSP page. This example will
    open a pdf file into a new browser without displaying the download
    "save" prompt.
    Function to call the JSP:
    private function downloadFlyer(event:Event):void {
    var jspLink:URLRequest = new
    URLRequest("jsp/downloadpdf.jsp?fileName=Fundraiser_flyer_2008.pdf");
    navigateToURL( jspLink, "_blank" );
    JSP code:
    <%@ page errorPage="error.jsp" %>
    <%@ page import="java.io.*" %>
    <%
    //Get the parameters
    String downloadFileName=request.getParameter("fileName");
    String fileName = application.getRealPath("/downloads/" +
    downloadFileName);
    File file = new File(fileName);
    if (!file.exists()) {
    throw new IOException("File does not exist.");
    // Get the size of the file
    long length = file.length();
    // You cannot create an array using a long type.
    // It needs to be an int type.
    // Before converting to an int type, check
    // to ensure that file is not larger than Integer.MAX_VALUE.
    if (length > Integer.MAX_VALUE) {
    throw new IOException("File too big.");
    response.reset();
    response.resetBuffer();
    response.setContentType( "application/pdf" );
    response.setHeader ("Content-Disposition", "filename=" +
    downloadFileName);
    //Prevent the Java error: "getOutputStream() has already
    been called for this response"
    out.clear();
    out = pageContext.pushBody();
    InputStream in = new FileInputStream(file);
    OutputStream output = response.getOutputStream();
    try {
    int curByte=-1;
    while( (curByte=in.read()) !=-1){
    output.write(curByte);
    } catch (IOException ioe) {
    ioe.printStackTrace(System.out);
    } finally{
    output.flush();
    in.close();
    response.flushBuffer();
    %>

  • How to display .swf files in java using eclips platform ???

    Here my java code plz some one help me...
    import javax.swing.*;
    import java.io.*;
    import java.net.MalformedURLException;
    import java.awt.*;
    import java.awt.event.*;
    public class DisplaySWF extends JFrame
        public JPanel  window_panel;//address_panel,
        public JLabel address_label;
        public JTextField address_tf;
        public JEditorPane window_pane,tree_pane,attr_pane;
        public JScrollPane window_scroll,tree_scroll,attr_scroll;
        TextArea t1,t2;
        JPanel pane;
        public JButton address_b, browse;
        public JLabel l,m;
        private Go go = new Go();
        JFrame f ;
        public DisplaySWF() throws IOException
        // Define address bar
        //tree_pane=new JEditorPane();
        //tree_pane.setBounds(650,50,300,250);
        //address_panel = new JPanel();
        //address_panel.setLayout(null);
        f= new JFrame("Web browser");
        f.setSize(1000,700);
        pane=new JPanel();
        pane.setVisible(true);
        pane.setLayout(null);
        f.setContentPane(pane);
        address_label = new JLabel(" address: ", SwingConstants.CENTER);
        address_label.setBounds(10, 10, 70, 30);
        pane.add(address_label);
        address_tf = new JTextField("",25);
        address_tf.setBounds(80,10,250,30);
        pane.add(address_tf);
        browse = new JButton("Browse");
        browse.setBounds(340, 10, 140, 30);
        browse.addActionListener(go);
        pane.add(browse);
        window_pane=new JEditorPane();
        window_pane.setBounds(10, 50, 600, 600);
        pane.add(window_pane);
        l=new JLabel("DOM Structure");
        l.setBounds(650,30,100,10);
        pane.add(l);
        t1=new TextArea();
        t1.setBounds(650,50,300,250);
        pane.add(t1);
        m=new JLabel("Attribute");
        m.setBounds(650,350,100,10);
        pane.add(m);
        t2=new TextArea();
        t2.setBounds(650,380,300,280);
        pane.add(t2);
        f.setVisible(true);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window_pane = new JEditorPane("http://www.yahoo.com")
            public boolean getScrollableTracksViewportWidth()
                return true;
    public class Go implements ActionListener
            public void actionPerformed(ActionEvent ae)
                JFileChooser fc = new JFileChooser();
                int result = fc.showOpenDialog(null);
                if (result == JFileChooser.APPROVE_OPTION)
                    File file = fc.getSelectedFile();
                    String sname = file.getAbsolutePath();
                    address_tf.setText(sname);
                    String ext=getFileExtension(sname);
                    try
                        if(ext.equals("swf"))
                            window_pane.setPage(address_tf.getText());
                            System.out.println("hi");
                    catch (MalformedURLException e)
                    {     // new URL() failed
                        window_pane.setText("MalformedURLException: " + e);
                    catch (IOException e)
                    {               // openConnection() failed
                        window_pane.setText("IOException: " + e);
       public String getFileExtension(String filename)
        if (filename == null)
                return null;
        int lastUnixPos = filename.lastIndexOf('/');
        int lastWindowsPos = filename.lastIndexOf('\\');
        int indexOfLastSeparator = Math.max(lastUnixPos, lastWindowsPos);
        int extensionPos = filename.lastIndexOf('.');
        int lastSeparator = indexOfLastSeparator;
        int indexOfExtension = lastSeparator > extensionPos ? -1 : extensionPos;
        int index = indexOfExtension;
        if (index == -1)
            return "";
        else
            return filename.substring(index + 1);
    public static void main(String args[]) throws IOException
      DisplaySWF wb = new DisplaySWF();

    Thanks for reply...
    but i search in the google about this topic...there is no results will appear..
    the problem is "i have to run program in the MacOS like extract all the
    .sit(StuffIt) extension files. These sit files same as zip files in the windows... we have one tool called StuffIt Expander but it is 3rd party tool. but here requirement is i have to write my own program to extract all the files same as zip file program...
    please do the needful..i am waiting for ur reply,,,

  • 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../...

  • How To Read RTF file in JAVA?  Using  iText?

    How To Read RTF file in JAVA?  Using  iText?.....
    import java.io.*;
    import com.lowagie.text.*;
    import com.lowagie.text.rtf.*;
    public class RTF3 {
    public static void main(String[] args) {
    // System.out.println("This example generate a RTF file name Sample.rtf");
    // Create Document object
    Document myDoc = new Document();
    try {
    // Create writer to listen document object
    // and directs RTF Stream to the file Sample.rtf
    RtfWriter2.getInstance(myDoc, new FileOutputStream("Sample.rtf"));
    // open the document object
    myDoc.open();
    // Create a paragraph
         Paragraph p = new Paragraph();
         p.add("Helloworld in Rtf file..amazing isn't");
         // Add the paragraph to document object
    myDoc.add(p);
    catch(Exception e) {
    System.out.println(e);
    //close the document
    myDoc.close();
    Exception in thread "main" java.lang.NoSuchMethodError: com.lowagie.text.Rectangle.width()F
         at com.lowagie.text.rtf.document.RtfPageSetting.rectEquals(RtfPageSetting.java:433)
         at com.lowagie.text.rtf.document.RtfPageSetting.guessFormat(RtfPageSetting.java:362)
         at com.lowagie.text.rtf.document.RtfPageSetting.setPageSize(RtfPageSetting.java:341)
         at com.lowagie.text.rtf.RtfWriter2.setPageSize(RtfWriter2.java:248)
         at com.lowagie.text.Document.open(Unknown Source)
         at view.RTF3.main(RTF3.java:23)
    CAN you HELP me?

    import com.lowagie.text.Document;
    import com.lowagie.text.rtf.parser.RtfParser;
    import java.io.FileInputStream;
    String inputFile = "sample.rtf";
    Document document = new Document();
    document.open();
    RtfParser parser = new RtfParser(null);
    parser.convertRtfDocument(new FileInputStream(inputFile), document);

  • How to display Doc file format in the JEditPane?

    At this time , JEditPane supports RTF and HTML file format ,but
    Could anyone tell me how to display DOC file format using JEditPane
    or other JTextComponents?
    Thx a lot!
    Caton

    Hi,
    there is no support for doc files (M$ Word?) in Java. You would have to create your own classes for that eventually subclassing JEditorPane, EditorKit, Document etc. As well you'd need your own reader for the doc format.
    The problem I see with that however is that there is nothing such as thedoc file format. Microsoft just saves anything produced by MS Word into files ending with .doc. But, if there is anything such as a .doc file format, it changes more often than the weather in April.
    Ulrich

  • How to display Pdf file in iPad site

    Hi
    How to display Pdf file in web page which can able to view in iPad safari?
    Thanks,
    Arun

    You can't really.
    You need to use DHTML in the swf-wrapper HTML file, usually a
    division wrapped iFrame, and load the PDF into the iFrame as an
    overlay to the Flash.

  • How to display flash file in adf pages

    how to display flash file in adf pages need help

    Thanks all,
    It is resolved.
    the code i am using to display a flash is below.
    <f:verbatim>
    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version
    =10,0,0,0" width="300" height="300" id="11gR1_aniH_grey" align="middle">
    <param name="allowScriptAccess" value="sameDomain" />
    <param name="allowFullScreen" value="false" />
    <param name="wmode" value="transparent" />
    <param name="movie" value="mx2004demo.swf" />
    <param name="quality" value="high" />
    <param name="bgcolor" value="#4d5c64" />     
    <embed src="../Images/mx2004demo.swf" quality="high" width="300" height="300" name="mx2004demo.swf" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false"
    type="application/x-shockwave-flash" wmode="transparent"
    pluginspage="http://www.adobe.com/go/getflashplayer" />
         </object>
    </f:verbatim>

  • How to display XSL file to ASPX in dreamweaver

    Hi,
    Just wondering how to display XSL file in ASPX page?
    I normally do it in ASP page by using server behaviour XSLT transformation and bind it to ASP page and this works very well.
    Now I am trying to use the same method and using ASPX page this time but this time there is no option from server behaviour where I can bind it to my ASPX.
    Can someone help or perhaps let me know where I can find the information how to do it?
    Thanks,
    Rush O

    You mean you want to see the XML source?
    You need to replace the characters '<' and '&' with corresponding entities '&lt;' and '&amp;'. You can use replaceAll, but do the ampersands first.
    Then I suggest you probably want to put them in a <PRE> block.

  • How to transfer pc file to Samsung using the adobe reader app?

    how to transfer pc file to Samsung using the adobe reader app?

    I solved the problem.  I manually created my own Adobe PDF folder by connecting the phone via usb to my PC, Windows Autoplay gave me the option to 'Open device to view files'. Explorer then displayed all the folders on the phone.  I created an Adobe PDF folder manually and copied the PDFs I wanted to view into that folder.  Adobe Reader then found the files without a problem.  I clearly was missing something quite simple but something I'm sure a lot of people would miss.  Perhaps if the next version of Adobe Reader for Android created this folder automatically, like Kindle and Kobo and other readers do, it might save a lot of people a bit of a headache.

  • How to upload Excel file in BI using function module in abap program

    How to upload Excel file in BI using function module in abap program?

    Hi Anuj,
    To upload the file , you can try a standard program "RSEPSFTP" .
    while you execute the program , a selection screen appears in which the inputs should be give as
    RFC destination - The target server name
    FTP command- PUT
    local file - your file name
    local directory - path of your local file
    remote file - your target file name
    remote directory - where it has to be stored
    Hope this is useful for you
    Thanks & regards
    Anju

Maybe you are looking for

  • ITunes from an External hard drive

    I just moved all of my iTunes music files to a La Cie mini hard drive. I set my iTunes preference to find the files on that drive. When I go to play a song in the library, it tells me it has to find the file. Once I manually locate it, it plays. How

  • Sort Filter Table Matrix

    Hi, I like to use the Sort Filter Table function (right click on the Matrix, plus the SAP icon to be activated) in my Add-On, Matrix. Could you please provide me the code? Thank you, Rune

  • [FAILED] - VGA2USB installation in ArchLinux. How do you install it?

    I have VGA2USB frame grabber device. Connected to my Archlinux. I want to use it and install it but cant make it installed. Help!! I have tried with latest the greatest kernel and then i switched to kernel26-lts both same, so please see as below my s

  • Problem of Visualization of Discoverer Report in Portal

    I have a report the Discoverer in PORTAL and the problem is that it is seen simultaneously too small and different from as visualizes in the Discoverer Plus or Discoverer Desktop. I have Discoverer and Portal version 9.0.4 Thanks

  • Recurring problem - need to touch report query to make page to work again

    Hello In my APEX 3.0 (Oracle 10.2.0.3.0) application I have a main menu which is a very simple page with one report that selects from a local table (no dblink) what pages the logged user has access to. The problem is that now and then (around once a