Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing exception in MVC model from servlet to JSP

 
Ashraf Fouad
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I'm using IBM implementation of MVC, and I want to handle exception thrown in the model part as follows:
1- Any exception thrown in the model part(business logic) is logged in files, and thrown to the caller function and so on.
2- Untill it reaches the Handler, which detect that exception was thrown, and redirect to errorpage.
3- I want to display the error message of the exception in the JSP, which has already the directive <%@ page isErrorPage="true" %>
I already done 1, 2, but I don't know how to pass the exception from Servlet to JSP.
anyone can help
 
Juanjo Bazan
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your servlet could place a bean with the error message as an attribute and place it within the request:
__________________________________________________
//msg is a string with the exception message
ErrorControlBean ecb = new ErrorControlBean();
ecb.setMessage(msg);
request.setAttribute("errorBean", ecb);
// do whatever else necessary
getServletConfig().getServletContext().getRequestDispatcher("/jsp/errorpage.jsp").forward(request, response);
__________________________________________________
then your errorpage.jsp can extract the bean and its properties:
__________________________________________________
<jsp:useBean id="errorBean" class="ErrorControlBean"
scope="request"/>
<jsp:getProperty name="errorBean" property="message" />
__________________________________________________

--HTH
Juanjo
[ June 17, 2002: Message edited by: Juanjo Bazan ]
 
Ashraf Fouad
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes this will work, but I wanted to use the implicit object in the error which is defined as error page
 
Erick Jones
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you set an attribute in the request with a key of "javax.servlet.jsp.jspException", then it will be available through the implicit 'exception' JSP variable.
For example,
request.setAttribute("javax.servlet.jsp.jspException", exception);
Regards,
Erick
 
Erick Jones
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you set an attribute in the request with a key of "javax.servlet.jsp.jspException", then it will be available through the implicit 'exception' JSP variable.
For example,
request.setAttribute("javax.servlet.jsp.jspException", exception);
Regards,
Erick
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic