1
我想在我的样式表没有被浏览器找到时显示原始XML,有可能吗?未找到引用xsl样式表时的默认浏览器xml样式表?
下面我把我的XML文档的标题。
<?xml version="1.0" encoding="UTF-8" standalone="no"?><?xml-stylesheet type="text/xsl" href="./my_sheet.xsl" title="relativeRef" alternate="YES"?>
当我的服务器上找不到样式表我将返回404错误,但是这使得浏览器停止并显示错误消息的XML解析器。我该怎么办?这是服务样式表的servlet的JAVA代码。
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
edamisUtils.log("Serving my_sheet.xsl");
//If we could not load my_sheet we throw a 404 error.
if(my_sheet== null){
edamisUtils.debug(5, "Did not find the my_sheet.xsl, sending a 404 status response.");
resp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
//Set the MIME type of the response to text/xsl
resp.setContentType("text/xsl");
OutputStream os = resp.getOutputStream();
os.write(my_sheet.array());
}
谢谢大家,祝你有美好的一天!
所以没有人有一个想法来解决这个问题? – Abbadon 2012-08-13 11:12:17
我不确定是否有可用的回退,因为它取决于每个浏览器的实现。创建XML时,必须动态包含此处理指令。 – kernel 2012-08-13 20:24:15
问题是,我不知道何时生成浏览器将读取它的XML。它会迫使我根据请求它的浏览器来动态地修改XML ... – Abbadon 2012-08-14 08:17:38