Error message : Can not call sendRedirect () after the response has been committed
Problem Description : In the case where the response has been redirected, behind which can have other respons redirection.
Code Display
if (adduser.getName() == "" || adduser.getName() == null) {
response.sendRedirect(request.getContextPath() + "/add.jsp");
}
int num = user.addUser(adduser);
if (num > 0) {
response.sendRedirect(request.getContextPath() + "/userListServlet");
}
Solution : plus return later in response to redirect the statement, after performing the first redirect response, the latter statement can not be executed, the problem is solved!
Demo code
if (adduser.getName() == "" || adduser.getName() == null) {
response.sendRedirect(request.getContextPath() + "/add.jsp");
return;
}
int num = user.addUser(adduser);
if (num > 0) {
response.sendRedirect(request.getContextPath() + "/userListServlet");
return;
}