Hi all,
I would like to ask for some help.
I made a java servlet. It receives information from sender through http get/post and it processes the information (for example it store received data to database).
My problem is how can I throw back an http 500 exception to the sender if there is an error during data processing?
My code:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ... PrintWriter out = response.getWriter(); try { ... Integer[] i = new Integer[1]; // it will throw an exception i[5] = Integer.valueOf(5); // out.println("ok"); } catch (Exception ex) { // TODO to write: send back HTTP 500 error throw new ServletException(ex); } finally { out.close(); } }
Thank you, alma