About Question enthuware.jwpv6.2.739 :

Moderator: admin

Post Reply
himaiMinh
Posts: 358
Joined: Fri Nov 29, 2013 8:26 pm
Contact:

About Question enthuware.jwpv6.2.739 :

Post by himaiMinh »

For the 4th option, "catch the exception, wrap into ServletException and define the ServletException to error-page mapping in web.xml.
This can be done, even though it is not the best way to handle exception.

Code: Select all

@WebServlet("/errorServlet")
public class MyServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
         try{
             throw new NotEnoughFundException();
         }
         catch (NotEnoughFundException e){
             throw new ServletException (e);
         }
    }
}

Code: Select all

 <error-page>
         <exception-type>javax.servlet.ServletException</exception-type>
         <location>/errorPage.jsp</location>
 </error-page>

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.jwpv6.2.739 :

Post by admin »

Correct. It is possible to do so but is not a sensible way (as required by the question). You should not map ServletException. You should map the exception wrapped by the ServletException to an error page.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests