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

Similar Messages

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

  • How to display XML file that XI sent to my j2ee appl?

    Hi,
    In my scenario File->XI->J2EE appl.
    I got XML page cannot be displayed.
    XML document must have a top level element. Error processing resource 'http://localhost:7001/Invoke/DisplayRes'.
    I deployed my .ear file on BEA Weblogic application server9.0
    I found no error when i tested in SXI_MONI and RWB->Message monitor as well.
    This is my servlet code:
    public class DisplayRes extends HttpServlet {
         public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         doPost(request,response);
         public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
         BufferedReader brin =new BufferedReader(new InputStreamReader(request.getInputStream()));
         String inputLine;
         StringBuffer sBuf = new StringBuffer();
         PrintWriter out = response.getWriter();
         response.setContentType("text/xml");
         while ((inputLine = brin.readLine()) != null)
             sBuf.append(inputLine);       
             //out.setContentType("text/xml");
             //out.println(sBuf.toString());
             out.write(sBuf.toString());
              brin.close();
             out.flush();
    What went wrong.All helpful answers are highly rewarded.
    Thanks

    Hi
    Can anyone tell me how XI sends messages to applications like J2EE. In REceiver comm channel, I think we specify about the target system like J2EE appl.
    Aadapter Type: HTTP
                   Receiver
    Transport Protocol:  HTTP1.0
    Message Protocol:    XI payload in HTTP body
    Adapter Engine:      Integration Server
    Addressing Type:     URL address
    Target host:         localhost
    Service Number:      7001(Port number of Weblogic appl server--where my J2EE appl is deployed).
    Path     :  /Invoke/DisplayRes/
    Authentication Type:Use Logon Data for SAP System
    Content Type: text/xml
    Username:   xiappluser
    password:   xx
    XML code:   UTF-8
    I suppose XI sends msgs to http://localhost:7001/Invoke/DisplayRes/........
    in this example if am correct?
    Then I have given all tyhe necessary setting but my servlet is not able to display XML msg in browser?
    This is my servlet code:
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
         PrintWriter out = response.getWriter();
         BufferedReader brin =new BufferedReader(new InputStreamReader(request.getInputStream()));
         String inputLine;
         StringBuffer sBuf = new StringBuffer();
            response.setContentType("text/xml");
         while ((inputLine = brin.readLine()) != null)
             sBuf.append(inputLine);
             out.println("hi");            
                out.println(sBuf.toString());
             brin.close();
             out.flush();
    What went wrong?
    Help me, all helpful answers are highly rewarded.
    Thanks

  • How to display XML file in java swing

    hi all
    now i do my M.Sc., project on data maining.this time i have one problem,thats i can't display XML file in swing frame.so any one know this plz give me that idea or code.
    Thanks to all.
    RSK

    One way of doing that is to use JDOM...
    u create an xml tree, and then output using XMLOutputter class...it will be displayed in text...im not sure if thats what u want...however, if u do want to represent it visually then u may need to draw a tree...u may use the Graphics2D for that...there are alot of ways to do such thing, and the 2 possibilities arent the best...depends on what u want...elaborate more pls.

  • How to display XML file as is it is in my browser using servlets???

    I have a question like my servlet receives an XML file in its request object. I just need display the same XML file as it is in my browser. How to do that? Please help me out. I have searched so many blogs, but i did not get right solution.
    My XML file file will be like this:
    <ns0:Http_Message_Type_Demo xmlns:ns0="http://abcdemo.com">
    <Name>A</Name>
    <RollNo>123</RollNo>
    <Address>a2</Address>
    </ns0:Http_Message_Type_Demo>
    Thnks

    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 display XML file(as markup) in jsp page..?

    Hi All,
    * I have to display the XML file(as markup) in jsp page (Tree Format)....
    * My XML file is an java.io.file object , and how to view this XML file on my JSP page...........
    Thanks in Advance,
    JavaImran

    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 display xml sting as tree , using af:tree

    Hi, i need to display a xml string stored in the data base table, as a xml tree in GUI.
    I understand ADF having a component called <af:tree> . It expects input data as "oracle.adf.view.faces.model.TreeModel" type.
    how to convert the string format of xml stored in the database , to the required type " "oracle.adf.view.faces.model.TreeModel"".
    Is there any examples to do this. Thanks .
    ganesh

    Thanks for the post.
    I looked at the link , before posting my question. That;s not i what i want. It says,
    The Oracle ADF Framework includes a Data Control for URL Services (a.k.a URL Service Data Control). The URL Service Data Control provides the ability to access files (CSV, XML) through a URL. You can also utilize this Data Control to access Servlets and JSPs that return simple, textual data such as XML data. In this How To, the URL Service Data Control will be used to access the JDeveloper RSS News feed and present that data within a Rich Client Interface. You will need JDeveloper 11g, available from OTN, to give this a try. Also provided is the Application that is utilized in this How-To.
    But what i want is entirely different than URL data control.
    A table is having xml file as string (The size can go upto 1 mb. )
    In the GUI i need to display it as tree.

  • How to send XML file into XI using sender HTTP adapter

    I am using HTTP sender adapter to post the XML file into XI. I tried to form the URL by using the following String query , but I am unable to execute file.
    String urlString = "http://<servername:portno>/sap/xi/adapter_plain?namespace=<namespace>&interface=<interface name>&service=<service name>&party=&agency=&scheme=&QOS=BE&sap-user=xiappluser&sap-password=satyam&sap-client=100&sap-language=EN";
    How can I execute xml file by using HTTP sender adapter.
    Any one with better suggestions, about this idea?
    Thanks in advance for all.
    Ram Raj

    Hi
    Just use the following parameter to send xml file using HTTP adapter.
    "http://xiserver:8000/sap/xi/adapter_plain?namespace="senderNamespace"&interface=senderinterface&service=sender service";
    "&party=sender party"&agency=&scheme=&QOS=BE&sap-user=userid &sap-password=password&sap-client=100&sap-language=D";
    with the help of this you are able to point out which interface you would like to use.
    And in payload pass the xml.
    and thats it
    carry on
    Cheers
    Regards
    Piyush

  • How to convert xml file to xsl using java

    Hi all,
    I have an XML file with which i need to convert(transform) it to an xsl file using java.
    I am new to converting xml file to xslt.Please send me if u have code .
    Thanks in advance
    regards
    Ram

    You seem to be asking the wrong question. An XSL file can be used to transform an XML file, but transforming an XML into an XSL does not make sense. The API for running XSL transforms on the Java platform is described here:
    http://java.sun.com/javase/6/docs/api/javax/xml/transform/package-summary.html

  • 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 Display XML in a UIWebView?

    Hi everybody. I like how Safari displays XML files and I would like to emulate that functionality in an iPhone UIWebView. However, I just can't get it to look the same when passing a URL to the UIWebView.
    For example, take a simple XML file like http://molottery.com/rss-num.xml. Viewing that in Safari looks okay, but passing that same URL into a UIWebView just shows a blank page.
    I changed the web protocol from http to feed (feed://molottery.com/rss-num.xml) and it launches the page in Safari instead of my UIWebView. Looks good, but it quit my app... :- (
    I noticed that XML files on the iPhone get re-routed through reader.mac.com so I tried appending that to my URL (http://reader.mac.com/mobile/v1/http://molottery.com/rss-num.xml) but that did not work either.
    When I tried URLEncoding the string like Safari does (http://reader.mac.com/mobile/v1/http%3A%2F%2Fmolottery.com%2Frss-num.xml) I get a UIWebView saying that "This Application Is Viewable Only On iPhone".
    So how can I emulate the regular Safari XML functionality inside my UIWebView? I will post my code upon request, if that will help. Any assistance from the Developer Community would be greatly appreciated.
    Thanks!

    You may have better luck in the iPhone dev forums...
    https://devforums.apple.com/community/iphone/web

  • HELP!!!! How to save xml file!!!Anyone can help???

    Hi,
    It is urgent for me to know how to save xml file. I use VC++6.0, Oracle xdk 9.0.0.0.0 or 9.0.0.0.0Abeta under windows98.
    It is OK to compile the program with print() method. But system will tell me there is illegal operation when I run it. If I delete the line with print(), the result will be normal.
    in class node, there is two functions
    void print(ostream *out = &cout, uword level = 0,uword step = 4);
    void print(DOMString buffer, size_t bufsize, uword level = 0, uword step = 4);
    Is there anyone who may tell me how to use them? to write back specific xml file?
    Without print(), I can not save the xml file...It seems in Oracle xdk9.0.0.0.0, there is no obvious function to save the file.(or because I am a new comer , not familier with DOM)
    Can anyone tell me how to save xml file? or just paste an example! It is very a little urgent to me...Hope you give me some ideas....
    Many thanks in advance!!!!
    yours,
    Fiena

    Hi,
    goto sxmb_adm > intergration engine configration > specific configration
    go in edit mode > new entry
    choose
    Category -> IDoc
    Parameters -> XML_CONVERSION
    current value -> 2
    Regards,
    Manisha

Maybe you are looking for

  • How do i setup a itunes store account without a credit card?

    how do i setup a itunes store account without a credit card? i need to setup a account for the album artwork please help.....

  • Moving Tool not working in Photoshop Elements 12 in Yosemite

    Hello, my moving tool for Photoshop 12 in Yosemite is not working. When I drag an object in the layer, it keeps snapping back to the center.  I've tried closing other programs, rebooting, different files, made a new file, made new layers, nothing. Th

  • How to export In-line Javascript to printed documentation?

    Hi Folks, I am working in Robohelp 8 HTML, and have created these wonderful javascript include files that allow me to generate numbered and bulleted list instructions and insert them into my help guide pages. Basically, the instructions are the same

  • Dear 12 Inchers" my screens peeling!

    I had to begin a new thread for this- in the corner of the screen of my beautiful 12 in. powerbook there appears to be an unraveling; it looks as if the corner within the lcd is lifting up if thats possible. It does not affect me too much but I'm afr

  • 3750G won't "age out" old arp table entries

    WS-C3750G-24TS running 12.2(20)SE4, RELEASE SOFTWARE (fc1). sho mac-address-table aging-time Vlan Aging Time 253 300 252 300 254 300 255 300 1 300 251 300 The aging is not working. I can failover some devices I have and the mac-address of the old dev