mmuncada
mmuncada

Reputation: 548

Will the code after sendRedirect() still be executed?

I'm curious how sendRedirect() works after it redirects.

MaintenanceController.java

@RequestMapping(produces = "text/html")
public String menu(HttpServletRequest request, HttpServletResponse response) throws IOException {
    if((new BaseController()).checkPrivilege(request) == "ADMIN") {
        return (new BaseController()).fallback(request, response);
    }
    return "maintenance/menu";
}

BaseController.java

public String fallback(HttpServletRequest request, HttpServletResponse response) throws IOException{
    return String.format("redirect:%s",request.getHeader("referer"));
}

public String checkPrivilege(HttpServletRequest request) {
     return (String)request.getSession().getAttribute("privilege");
}

It's not like I could just put system.out.print() after the sendRedirect() to print something if it would execute immediately after. I would like to know if at some point in time it will still execute the code after it. In this case the return "maintenance/menu";.

Upvotes: 1

Views: 1962

Answers (1)

Amer Qarabsa
Amer Qarabsa

Reputation: 6574

This is a normal java code after all, after the control is done with processing the "sendRedirect()" it will continue the execution.

Upvotes: 2

Related Questions