Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java servlets - stop executing and redirect on error

Tags:

java

servlets

I have the following bit of code in my java servlet:

if(passenger == null){
            response.sendError(400, "The specified passenger does not exist.");
        }

The page does redirect to the error page, however, the rest of the servlet code is still executed. How do I redirect and sort of 'break' out of the servlet?

like image 577
Matt Avatar asked Jul 15 '26 01:07

Matt


1 Answers

if(passenger == null){
            response.sendError(400, "The specified passenger does not exist.");
    return; //or return null; depending on return type of method
}
like image 106
jmj Avatar answered Jul 16 '26 14:07

jmj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!