public class List extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) { response.setContentType("text/xml"); Document doc = null; try { try { doc = new Jokes(getServletContext()).getJokes(); } catch (IOException e) { throw new ServletException("Unable to get jokes "+ e.getMessage()); } catch (JDOMException e) { throw new ServletException("Unable to create new document "+ e.getMessage()); } XSLTransformer t = null; try { t = new XSLTransformer( getServletContext().getInitParameter("CategoriesXSLT") ); } catch (XSLTransformException e) { throw new ServletException("Failed to create XSLT "+ e.getMessage()); } Writer out = null; try { out = response.getWriter(); } catch (IOException e) { throw new ServletException("Unable to create writer "+ e.getMessage()); } try { new XMLOutputter().output(t.transform(doc), out); } catch (XSLTransformException e) { throw new ServletException( "Failed to perform XSL Transformation "+e.getMessage()); } catch (IOException e) { throw new ServletException("Failed to output document "+ e.getMessage()); } } catch (ServletException e) { log(e.getMessage); response.sendError(500, "Internal error"); } } }