【发布时间】:2012-08-10 09:37:23
【问题描述】:
我希望在浏览器找不到我的样式表时显示原始 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());
}
谢谢大家,祝你有美好的一天!
【问题讨论】:
-
所以没有人想办法解决这个问题?
-
我不知道是否有可用的回退,因为它取决于每个浏览器的实现。您必须在创建 XML 时动态包含此处理指令。
-
问题是我不知道生成 XML 时哪个浏览器会读取它。它会迫使我根据请求它的浏览器动态修改 XML...
-
这是每个 Web 内容的问题 :) 但是当 XSL 不可用时您要求回退,而不是浏览器确定。还是我错了?
-
你说得对,当 XSL 不可用时,我想要一个后备。