Exception handling in JSP developed using tags


Web tier: servlets, JSP, Web frameworks: Exception handling in JSP developed using tags

  1. Exception handling in JSP developed using tags (5 messages)

    Hi all, We have created the web pages using struts-tiles framework. In the layout.jsps we have various used to insert the JSPs or the definitions. Now the problem is that whenever any JSP which is inserted in layout using tiles:insert throws RuntimeExceptions the page continues to be displayed. I would obviously like to display the error page using configuration in web.xml and errorPage="" construct. This is not happening. At the maximum the tile which has failed can only be forwarded to the error page defined for the web-app. I would like the whole page to be shown as error page. I have gone through number of mailing lists and found that similar problem people are facing. Can anyone throw some light on this?? Thnx in Advance, Amit
  2. Looks like encountering a bug in struts - tiles related code... very old log in the mailing list... http://www.mail-archive.com/struts-user at jakarta dot apache dot org/msg97141.html Bhagvan K http://www.jroller.com/page/bhagvank
  3. Thnx for the link. I had checked that earlier. There is no resolution as such for the same though. thnx amit
  4. Hello, I have got a workaround to do this.Posting here so that if someone needs similar info. this can be used. Also let me know if anyone has any better ideas to achieve this. 1) Introduce a new class MyTilesUtilStrutsImpl which extends the class TilesUtilStrutsImpl. ******************Java code ************************* public class MyTilesUtilImpl extends TilesUtilStrutsImpl { /** * Do an include using PageContext.include(). * * This method is used by the Tiles package when an include is required. * The Tiles package can use indifferently any form of this method. * @param uri Uri or Definition name to forward. * @param pageContext Current page context. */ public void doInclude(String uri, PageContext pageContext) throws IOException, ServletException { try { System.out.println("MyTilesUtilImpl::before including::uri=="+ uri); pageContext.include(uri); System.out.println("MyTilesUtilImpl::after including::uri=="+ uri); } catch(Exception e) { System.out.println("MyTilesUtilImpl::doInclude::Exception redirect"); e.printStackTrace(); ((HttpServletResponse)pageContext.getResponse()).sendRedirect("http://localhost:7001/consumerProducts/displayError.do"); //((HttpServletResponse)pageContext.getResponse()).sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); //pageContext.getOut().write(""); } } } ******************Java code ************************* 2) In this class override the public void doInclude(String uri, PageContext pageContext) which is usually called from the INSERT tag. ( I have debugged this in original JAR) 3) Catch the exception and do a sendRedirect() to the action URI which would forward it to the error page. 4) The tiles:insert used should also set another attribute flush="false" so that the content is not flushed to browser. This means that the whole page would be rendered on client browser at once. 5) Modify the struts-config.xml as mentioned below so that TilesPlugin picks up the MyTilesUtilStrutsImpl for processing the requests. <!-- excerpt from struts-config file --> <!-- Path to XML definition file --> <!-- Set Module-awareness to true --> <!-- excerpt from struts-config file --> If we do this then the error page would come whenever one of the tiles fails. Please see the sendRedirect() URL mentioned in the Java file. regards, Amit
  5. Hi Amit, sendRedirect is working in this case. I tried the same but not displying the error page or not redirecting to any URL even.
  6. Hi Amit, Sorry, sendRedirect is not working in this case. I tried the same but not displying the error page or not redirecting to any URL even.