Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this:</p> <p>I changed your validate to return a boolean, so you can run an if statement on it in the doPost method. I also made it return a success instead of failure, just so the check makes more sense once you've returned.</p> <p>response.sendError will allow you to do a generic error page (See this: <a href="http://blogs.atlassian.com/2007/07/responsesenderror_vs_responses/" rel="nofollow">http://blogs.atlassian.com/2007/07/responsesenderror_vs_responses/</a>) instead of your output. If you want that you'll want setStatus (again, see the link).</p> <p>The return should terminate execution and prevent the rest from happening, but it won't shut down the servlet like a system.exit(0) would.</p> <pre><code>public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException{ String param1 = request.getParameter("param1"); String param2 = request.getParameter("param2"); if (! validateInput(param1, param2, request, response)){ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); //Or you can use this instead... //response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); //PrintWriter out = response.getWriter(); //out.write("invalid input"); return; } //if nothing's wrong with the input, do this and that } private boolean validateInput(String param1, String param2, HttpServletRequest request, HttpServletResponse response) throws IOException{ boolean success = false; //validate input blah blah blah return success; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload