Java 捕获servlet中语句引发的异常会停止执行(不显示输出)
公共类上载扩展了HttpServlet{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
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(“处理错误”);.Commentout.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>