java - response.sendRedirect() from jsp:include being ignored? -



java - response.sendRedirect() from jsp:include being ignored? -

i've got jsp file, includes jsp file check values , such:

<jsp:include page="setup.jsp" />

inside setup.jsp i've got conditional code determines if needed values set in session , if not redirects them different page. or @ to the lowest degree supposed to, redirect seems getting ignored.

system.err.println("redirecting!"); response.sendredirect("http://www.google.com"); return;

i see "redirecting!" logged console, page continues on , renders normally. had curl dump headers me , saw response http/1.1 200 ok isn't sending 302 redirect.

any thought problem , how can prepare this?

edit: have verified response not yet committed. response.iscommitted() returns false meaning status code , headers have not been sent yet.

edit 2: i've tried calling response.sendredirect() in many other places , find can redirect before . redirect within jsp seems ignored , if seek redirect right after jsp illegal state exception because response has been committed.

the <jsp:include> uses under covers requestdispatcher#include(). click link see javadoc. here's extract of relevance (emphasis mine):

...

the servletresponse object has path elements , parameters remain unchanged caller's. the included servlet cannot alter response status code or set headers; effort create alter ignored.

...

the httpservletresponse#sendredirect() sets http response status 302 , http location header target url. totally beingness ignored.

the deeper problem you're abusing jsp page controller/filter. should using normal servlet or filter class runs far before jsp.

java jsp redirect jspinclude

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -