How do you display xml file with xlst sheet in jsp

I have an xml file with accompanying xslt file (and several images that are used in a single directory. If I doubleclick on the xml file, it displays perfectly in my browser - Formatting, images and all!
          The 100 dollar question - How do I duplicate this behavior in a JSP page in WebLogic 8.1 using the code in the xml and the accompanying xslt (formatting) file? I tried simple embedding the xml code in the jsp, but that didn't seem to work. What is the secret?
          Okay, I need to add a bit more information here. I understand that it is really easy to just redirect to the XML file. The issue is really security. I want the XML to be inside a jsp that will only allow validated users to view it.
          Another way to look at the problem would be, can I add a jsp security tag to the xml file? Or how to I add the xml code inside a jsp and keep the path references to the xslt and graphics.
          Hope the added information helps
          Thanks,
          Ken
          Message was edited by: KLee - 20050609 10:25 MST
          [email protected]

This proved out to be the answer. Thanks for the direction!
          import java.io.File;
          import java.io.IOException;
          import java.io.InputStream;
          import java.io.OutputStream;
          import java.io.FileNotFoundException;
          import java.io.FileOutputStream;
          import javax.servlet.ServletException;
          import javax.servlet.http.HttpServlet;
          import javax.servlet.http.HttpServletRequest;
          import javax.servlet.http.HttpServletResponse;
          import javax.xml.transform.Transformer;
          import javax.xml.transform.TransformerConfigurationException;
          import javax.xml.transform.TransformerException;
          import javax.xml.transform.TransformerFactory;
          import javax.xml.transform.stream.StreamResult;
          import javax.xml.transform.stream.StreamSource;
          public class XML_XSLT_Servlet extends HttpServlet {
          protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
                    String xmlfile = req.getParameter("xmlfile"); if (xmlfile==null) xmlfile = "test.xml";
                    String xsltfile = req.getParameter("xsltfile"); if (xsltfile==null) xsltfile = "test.xslt";
                    /* Test if file exists!, or use default file */
                    File f1 = new File(getServletContext().getRealPath("WEB-INF/displayfiles/"), xmlfile);
                    File f2 = new File(getServletContext().getRealPath("WEB-INF/displayfiles/"), xsltfile);
               if (f1.exists() && f2.exists()) {
                         // System.out.println("Files Found");
                    } else {
                         System.out.println("XML and XSLT Files NOT Found");
                         System.out.println(f1.getPath());
                         System.out.println(f1.getName());
                         xmlfile = "test.xml";
                         xsltfile = "test.xslt";
          InputStream fileXML = getServletContext().getResourceAsStream("WEB-INF/displayfiles/" + xmlfile);
          InputStream fileXSLT = getServletContext().getResourceAsStream("WEB-INF/displayfiles/" + xsltfile);
          OutputStream os = res.getOutputStream();
          TransformerFactory xFactory = TransformerFactory.newInstance();
          StreamSource stylesheet = new StreamSource(fileXSLT);
          Transformer xformer = null;
          try {
          xformer = xFactory.newTransformer(stylesheet);
          } catch (TransformerConfigurationException tfce) {
          tfce.printStackTrace();
          StreamSource input = new StreamSource(fileXML);
          StreamResult output = null;
          try {
          output = new StreamResult(os);
          } catch (Exception e) {
          e.printStackTrace();
          try {
          xformer.transform(input, output);
          } catch (TransformerException xfe) {
          xfe.printStackTrace();
          <pre></pre><pre></pre>

Similar Messages

  • How to validate an XML file with XSD Schema on JDK 1.4

    Hi
    I'm looking for samples how to validate xml files with xsd schema using jsdk 1.4
    Thank you.

    This is how.
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.transform.dom.DOMResult;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.validation.Schema;
    import javax.xml.validation.SchemaFactory;
    import javax.xml.validation.Validator;
    DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
    dbfac.setNamespaceAware(true);
    SchemaFactory factory1 = SchemaFactory
                        .newInstance("http://www.w3.org/2001/XMLSchema");
    Schema schema = factory1.newSchema(new File("person.xsd"));
    dbfac.setSchema(schema);
    DocumentBuilder dbparser1 = dbfac.newDocumentBuilder();
    Document doc1 = dbparser1.parse(new File("person.xml"));
    Validator validator1 = schema.newValidator();
    DOMSource dm1 = new DOMSource(doc1);
    DOMResult domresult1 = new DOMResult();
    validator1.validate(dm1, domresult1);

  • How Can I dispaly XML file with CSS?

    hi,all
    There is maybe a simple way to dispaly a XML file with a CSS file in program.But I don't know.Who can tell me?
    Thank you very much!

    Hi,
    XML documents don't have the link or style elements that are used in HTML to connect style information to particular documents. Instead, the W3C has defined a processing instruction that provides that information, based on the model of the HTML link element. To connect a CSS style sheet to your XML document so that the browser can find it, use a processing instruction like
    <?xml-stylesheet type="text/css" href="URI"?>
    where URI is the address of the style sheet. We'll use a style sheet called display1.css for our first test document. The processing instruction can go right after the XML declaration.
    <?xml version="1.0" ?>
    <?xml-stylesheet type="text/css" href="display1.css"?>
    <test>
    Hope this may help you.
    Regards,
    Anil.
    Technical Support Engineer.

  • How to validate the Xml File With Java

    Hi,
    Can pls tell me. I want to validate the XML File for the Some Mandartory TAG. if that if Tag null i want to generate error xml file with error and i want move another folder with java. pls help me as soon as possible

    Use a validating parser (any recent Xerces, for one) and switch on the validation feature. Very much vendor-specific, so look at the docs of your parser. Oh, you do have a schema for these documents, don't you?

  • How To read an XML file with JDom

    I have read through some tutorials after installing JDom on how to read an existing XML file and I was confused by all of them. I simply want to open an XML file and read one of the node's content. Such as <username>john doe</username> this way I can compare values with what the user has entered as their username. I am not sure were to start and I was hoping someone could help me out.
    I know that this seems like an insecure way to store login information but after I master opening and writing XML files with JDom I am going to use AES to encrypt the XML files.

    Here is a test program for JDom and XPath use considering your XML file is named "test.xml" :import org.jdom.input.*;
    import org.jdom.xpath.*;
    public class JDomXPath {
    public static void main(String[] args) {
      SAXBuilder saxBuilder = new SAXBuilder("org.apache.xerces.parsers.SAXParser");
      try {
       org.jdom.Document jdomDocument = saxBuilder.build("test.xml");
       org.jdom.Element usernameNode = (org.jdom.Element)XPath.selectSingleNode(jdomDocument, "//username");
       System.out.print(usernameNode.getText());
      } catch (Exception e) {
       e.printStackTrace();
    }(tested with Eclipse)

  • How can i send xml file with a http servlet request

    Hi
    Please tell me how can I send a xml file into http servlet request.
    I have a servlet(action) java file.From this servlet I have generate a xml file. Now I need to send that xml file to another servlet with http servlet request object.
    Dave.

    When you say you have generated an XML file what do you mean?
    Is it a file stored on disk? Then pass the file path as a string to the servlet.
    Is it stored in memory as an object? The pass a reference to the object to the servlet.
    Or are you asking how to communicate between servlets?
    Look in the JavaDocs for the RequestDispatcher class. You can use this class to forward the request to another servlet. Data can be passes using the RequestDispatcher by storing it as attributes using the request getAttribute and setAttribute methods. Also described in the JavaDOcs.
    http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/RequestDispatcher.html

  • How to "use" a xml file with a script?

    Hey Guys!
    I use the normal Button with the send-option to send the xml file to an url.
    My question is how it's possible to work in a php-script with the xml data out of the formular?
    Thanks for help.
    LG
    Adrian

    Hi,
    I need to read a XML document with StringReade class.
    My aplication receives an absolute path but this
    doesn't work:
    StringReader oStringReader =
    new StringReader(c:\java\libros.xml);
    However it works with:
    StringReader oStringReader =
    new StringReader("<?xml version="1.0" e......");
    ie, with the whole document as a String, but I need
    to do it as the frist way.
    Thankstake a look at this link:
    http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/sax/2a_echo.html

  • How to download the xml file with netweaver 2004s

    I am trying to find the xml file in order to link R/3 to my portal
    I installed Netweaver 2004s but I am not able to link to R/3
    I heard that I can use another xml file from another server and download it and change the config to match the new server
    JF

    Hi JF,
           Michael is right in EP5, system are defined in XML file. use the following properties you will able to create system connecting to R/3.
    choose System Administration->&#61472;System Configuration-> System Landscape.
    Create a  system of  SAP_R/3_Dedicated type system
    Select the <b>Connector</b> from the Property category dropdown
    Application Host : <R/3 Host name>
    SAP Client: <Clent no>
    SAP System ID (SID):
    Server Port: 
    SAP System Number
    System Type: SAP_R3
    Select the <b>User Management</b> from the Property category dropdown
    Logon Method - UIDPW
    User Mapping Type - Admin,user
    Select <b>System Aliases</b> in the Edit dropdown list.
    This opens the System Alias Editor, and displays the existing list of aliases created for this system. Add the system alias here.
    Select the <b>test connection</b> in the Edit dropdown list:
    test the connection
    Hope this will solve your problem.
    Thanks
    Sai

  • How do you validate XML file against a Schema?

    Are there free applications that does that?

    Thanks, but how do you validata the Schema itself, which is an XML file.
    I know the schema DTD is online, but still I need some utility to do it
    Thanks

  • How do you run .exe files with wine by clicking on them?

    Hi, I need help with using wine on mac osx. I used to use wine on Ubuntu and Linux Mint and it was relatively simple. But on mac osx, I used macports to dowload/install wine, and i used winecfg to create a prefix. I can not figure out for the life of me how to launch an executable by clicking on it. It opens in TextEdit instead of launching in wine. Can someone explain to me how to make a .exe file launch by clicking on it? Do i have to register the filetype with wine? Wine is not in a .app format. I can run any .exe in terminal but it is less than convenient. Thanks in advance.

    So wrap Wine in an application, and bind the .exe's to the wrapper application.
    Platypus (free download)
    <http://www.versiontracker.com/dyn/moreinfo/macosx/19870>
    Can be used to turn any Unix program or script into a double clickable application, as well as a drag and drop target application.
    It should be possible to wrap Wine with Platypus.
    As an alternative, you might try Applications -> Automator -> Run Shell Script workflow, and save that as an application. Then bind your .exe's to that workflow you created.
    NOTE: I have not played with Wine, so your mileage may vary.

  • How to save an XML file with a proper name and how to maintain the history?

    Hi All,
    As per the requirement, I have to remane the name of the XML file which is under the KM repository Userhome/personaldocuments based on the user logon information.
    I have created a Repository service for the same and following is the code for the same. The service is working, but only for the first entry in the XML form. Second onwards, the file does not get remaned to the preferred one.
    Request you to throw some light as what is wrong or missing in the code, so that I can follow the right approach. Many thanks in advance.
    // Code snippet is here//
    //Starts here//
    com.sap.security.api.IUser epUser;
                                            epUser = UMFactory.getAuthenticator().getLoggedInUser();
                                     String EntID = epUser.getUniqueName();
    IResourceContext resContext = null;
    try {
         resContext = ResourceFactory.getInstance().getServiceContext("cmadmin_service");
    } catch (ResourceException e1) {
              e1.printStackTrace();
    RID rid = RID.getRID("/userhome""/"EntID+"/Personal Documents");
    IResource resource = null;
    try {
         resource = (ResourceFactory.getInstance().getResource(rid, resContext));
    } catch (ResourceException e2) {
              e2.printStackTrace();
    ICollection collection = (ICollection)resource;
    IResourceList resourseList = null;
    try {
         resourseList = collection.getChildren();
    } catch (AccessDeniedException e3) {
              e3.printStackTrace();
    } catch (ResourceException e3) {
              e3.printStackTrace();
         for(int i=0;i<resourseList.size();i++){
              IResource res_new = resourseList.get(i);
                try {
                   res_new.rename("Address_new.xml");
              } catch (NotSupportedException e) {
                                  e.printStackTrace();
              } catch (AccessDeniedException e) {
                                  e.printStackTrace();
              } catch (ResourceException e) {
                                  e.printStackTrace();
    //Code ends here//
    Regards
    DK
    Edited by: DIPENDRA MOHANTY on Jun 5, 2009 5:20 PM

    Hi,
    The code seems ok.
    But you have mentioned about a KM Rep service, what service is that? which event it is listening to?
    Regards
    BP

  • How do you include extra files with an AIR for iOS Publish?

    I've seen people mention they can include .html, .js, etc files with their iOS for AIR publish when making an iOS application from flash.
    What I haven't seen is how these people include extra files (html, css, images, videos, etc) to be packaged into the IPA during publish.
    How is this accomplished?

    --deleted--
    Sorry, figured it out.

  • How to generate a xml file with JSP?

    Hi,
    I want to dynamically generate maths formula in my web page. I think MathMl is a good choice. However, it needs xml file. I try to use JSP to generate the
    content of the xml file. However, it doesn't work. What should I do?
    Best regards.

    Hi,
    Thanks a lot for your replies. I used to write JSP to present quiz fetching from a database. To use MathML, xml file has to be used. I've tried to copy the content of the xml file to a jsp file and let the brower to display it. However, it doesn't work. I view the content of the page displayed by the brower. I simply contain nothing. So what it's the most convenience way to present the MathML dynamically.
    Best regards.
    From hoifo

  • How can you save a file with CS4 so that it can be opened with CS3?

    I fave a file that I have sent someone, but they can't open it because they don't have CS4. How can I save a file, using CS4, so that the file can be opened with CS3?
    Thanx

    From the help file: http://help.adobe.com/en_US/Illustrator/14.0/WS714a382cdf7d304e7e07d0100196cbc5f-655fa.ht ml

  • How to read a xml file with StringReader class

    Hi,
    I need to read a XML document with StringReade class. My aplication receives an absolute path but this doesn't work:
    StringReader oStringReader =
    new StringReader(c:\java\libros.xml);
    However it works with:
    StringReader oStringReader =
    new StringReader("<?xml version="1.0" e......");
    ie, with the whole document as a String, but I need to do it as the frist way.
    Thanks

    Hi,
    I need to read a XML document with StringReade class.
    My aplication receives an absolute path but this
    doesn't work:
    StringReader oStringReader =
    new StringReader(c:\java\libros.xml);
    However it works with:
    StringReader oStringReader =
    new StringReader("<?xml version="1.0" e......");
    ie, with the whole document as a String, but I need
    to do it as the frist way.
    Thankstake a look at this link:
    http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/sax/2a_echo.html

Maybe you are looking for