Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 捕获servlet中语句引发的异常会停止执行(不显示输出)_Java - Fatal编程技术网

Java 捕获servlet中语句引发的异常会停止执行(不显示输出)

Java 捕获servlet中语句引发的异常会停止执行(不显示输出),java,Java,公共类上载扩展了HttpServlet{ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.ge

公共类上载扩展了HttpServlet{

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) 
    {

        String img=request.getParameter("upload");

        Blob image=new SerialBlob(img.getBytes());

        HttpSession hs=request.getSession();

        int id=(Integer) hs.getAttribute("id");
        out.println("id "+id);
        int status=Dao.upload(image,id);

    } 
    catch (SQLException ex) {

    }
}
//在这里,我使用Blob数据类型获取图像的字节以将其存储在数据库中,该语句抛出SQLException,我为其编写了catch块。 现在,这个catch块正在停止程序以打印“id”(print语句不工作)

}
这些是我的doGet()和doPost()方法。

异常在
println
之前抛出,异常被吞没,因此没有输出。在catch块中,考虑添加:<代码> Out.PrtLn(“处理错误”);
.Comment
out.println(“id”+id)并尝试。。如果错误仍然存在,请在catch块中键入
ex.printStackTrace()
,并将stacktrace张贴在此处
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    processRequest(request, response);
}

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    processRequest(request, response);
}

/**
 * Returns a short description of the servlet.
 *
 * @return a String containing servlet description
 */
@Override
public String getServletInfo() {
    return "Short description";
}// </editor-fold>