将错误/异常重定向到HTML页面

时间:2013-08-22 08:01:48

标签: java html xml xslt exception-handling

需要将我在catch块中找到的错误和异常重定向到.html页面 这是我现在想要的代码,如果任何时候找不到任何文件,那么它应该重定向到.html页面或者borwser

    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 个答案:

没有答案