I would like the raw XML to be displayed when my stylesheet is not found by the browser, is it possible?
Below I have put the header of my XML document.
<?xml version="1.0" encoding="UTF-8" standalone="no"?><?xml-stylesheet type="text/xsl" href="./my_sheet.xsl" title="relativeRef" alternate="YES"?>
When the stylesheet is not found on my server I return a 404 error but this makes the XML parser of browser stop and displaying an error message. What should I do? Here is the JAVA code of the servlet which serves the stylesheet.
@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());
}
Thanks all and have a nice day!
Instead of returning a 404, you could return a 200 and a "copy-all" XSL.
Something like
if(my_sheet == null){
copy the copy_all XSL in the response output stream;
}
A copy-all XSL example can be found here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.