如何在输出HTML文件中打印错误日志

时间:2013-08-27 09:02:47

标签: java html xml

如何使用Java

在输出HTML文件中打印错误日志

我试图通过使用xslt将xml转换为html.But输出我在html文件中获取。现在我在java代码中处理一些FileNotFoundexception,现在假设万一找不到文件,那么我希望在输出HTML页面上抛出该错误

按照PSB的要求提供代码

public class XmlToHtml { public static void main(String [] args){

if (args.length == 3 && args.length !=0) {
    String dataXML = args[0];
    String inputXSL = args[1];
    String outputHTML = args[2];

    XmlToHtml xmltoHtml = new XmlToHtml();
    try {
        xmltoHtml.transform(dataXML, inputXSL, outputHTML);
    } catch (TransformerConfigurationException e) {
        e.printStackTrace();
        System.out.println("TransformerConfigurationException" + e);
    } catch (TransformerException e) {
        e.printStackTrace();
        System.out.println("TransformerException" + e);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        System.out.println("FileNotFoundException" + e);
    }
} else {
    System.err.println("Wrong Input");
    System.err
            .println("Please Enter in the follwing format : Data.xml Input.xsl            Output.html");
}
}

    public void transform(String dataXML, String inputXSL, String outputHTML)
    throws FileNotFoundException, TransformerException,
    TransformerConfigurationException {
     TransformerFactory tFactory = TransformerFactory.newInstance();
    Source xslDoc = new StreamSource(inputXSL);
     Source xmlDoc = new StreamSource(dataXML);
     OutputStream htmlDoc = new FileOutputStream(outputHTML);
     Transformer transformer = tFactory.newTransformer(xslDoc);
     transformer.transform(xmlDoc, new StreamResult(htmlDoc));
     Desktop dk = Desktop.getDesktop();
     try {
        dk.open(new File(outputHTML));

       } catch (IOException e) {
    // TODO Auto-generated catch block
      e.printStackTrace();
     }
 }

0 个答案:

没有答案