• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSTL c:redirect doesn't work from included jsp file  RSS feed

 
Allan Wang
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I tried to redirect jsp page from header.jsp to another jsp file, but it looks to me it doesn't work. The code looks like this:

test.jsp
<jsp:include page="header.jsp"/>

header.jsp
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<body>
<c:redirect url="http://java.sun.com" />

It will not redirect my test.jsp page to http://java.sun.com. But it can work if I put <c:redirect url="http://java.sun.com" /> in the test.jsp.

Could someone shed some light on?

Thank you!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following is from the description of the RequestDispatcher.include() method:

The ServletResponse object has its path elements and parameters remain unchanged from the caller's. The included servlet cannot change the response status code or set headers; any attempt to make a change is ignored.


No headers means no redirects.
 
Allan Wang
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your quick response, Bear.

So it means we can not redirect the page from the included or imported jsp file, right?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct, you cannot do anything that requires changing headers or return codes.

More precisely stated: any changes you make to the headers or the return code are ignored. So the <c:redirect> tag is probably working perfectly; it's just that its results (setting the redirect headers) are being discarded.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!