| 1218 | |
| 1219 | |
| 1220 | @Override |
| 1221 | public void sendRedirect(String location, int status, boolean clearBuffer) throws IOException { |
| 1222 | if (isCommitted()) { |
| 1223 | throw new IllegalStateException(sm.getString("coyoteResponse.sendRedirect.ise")); |
| 1224 | } |
| 1225 | |
| 1226 | // Ignore any call from an included servlet |
| 1227 | if (included) { |
| 1228 | return; |
| 1229 | } |
| 1230 | |
| 1231 | // Clear any data content that has been buffered |
| 1232 | if (clearBuffer) { |
| 1233 | resetBuffer(true); |
| 1234 | } |
| 1235 | |
| 1236 | // Generate a temporary redirect to the specified location |
| 1237 | try { |
| 1238 | Context context = getContext(); |
| 1239 | // If no ROOT context is defined, the context can be null. |
| 1240 | // In this case, the default Tomcat values are assumed, but without |
| 1241 | // reference to org.apache.catalina.STRICT_SERVLET_COMPLIANCE. |
| 1242 | String locationUri; |
| 1243 | // Relative redirects require HTTP/1.1 or later |
| 1244 | if (getRequest().getCoyoteRequest().getSupportsRelativeRedirects() && |
| 1245 | (context == null || context.getUseRelativeRedirects())) { |
| 1246 | locationUri = location; |
| 1247 | } else { |
| 1248 | locationUri = toAbsolute(location); |
| 1249 | } |
| 1250 | setStatus(status); |
| 1251 | setHeader("Location", locationUri); |
| 1252 | if (clearBuffer && context != null && context.getSendRedirectBody()) { |
| 1253 | PrintWriter writer = getWriter(); |
| 1254 | writer.print(sm.getString("coyoteResponse.sendRedirect.note", Escape.htmlElementContent(locationUri))); |
| 1255 | flushBuffer(); |
| 1256 | } |
| 1257 | } catch (IllegalArgumentException e) { |
| 1258 | log.warn(sm.getString("response.sendRedirectFail", location), e); |
| 1259 | setStatus(SC_NOT_FOUND); |
| 1260 | } |
| 1261 | |
| 1262 | // Cause the response to be finished (from the application perspective) |
| 1263 | setSuspended(true); |
| 1264 | } |
| 1265 | |
| 1266 | |
| 1267 | @Override |