Servlet-异常处理

①当Servlet抛出一个异常时,在web.xml使用error-page元素指定对特定异常或Http状态码做出相应的Servlet调用

示例:

@WebServlet("/errorHandler")
public class ErrorHandler extends HttpServlet{
    
    @Override
    public void doGet(HttpServletRequest req,HttpServletResponse resp) throws IOException,ServletException {
    resp.setContentType("text/html;charset=UTF-8");
    PrintWriter out = resp.getWriter();
    out.println("

" + "error handler" + "

"); } @Override public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException { doGet(request,response); } }

    
        errorHandler
        com.ryan.biz.ErrorHandler
       
    
        errorHandler
        /errorHandler
    

    
        404
        /errorHandler
    

    
        java.io.IOException
        /errorHandler
    


Servlet-异常处理_第1张图片

你可能感兴趣的:(Servlet)