the bosxcz
the bosxcz

Reputation: 91

JSTL with response.sendRedirect

Why is that jstl is not working(blank results) with

response.sendRedirect(url);

and jstl is working with

request.getRequestDispatcher(url).forward(request,response);

EDIT: in my jsp

<c:forEach items="${requestScope.(List from servlet)}" var="s">
<h1><c:out value="${s.(variable from list)}"></c:out></h1>
</c:forEach>

Upvotes: 1

Views: 1444

Answers (1)

JB Nizet
JB Nizet

Reputation: 691755

You don't seem to understand what a redirect is. A redirect consist in sending a response to the browser telling it to send a new GET request to a given URL. So obviously, the attributes you stored in the request before the sendRedirect() call are not available anymore when the JSP is executed, since it's executed as a response to another, different HTTP request.

A redirect is typically used as part as the redirect-after-post pattern. Otherwise, if you simply want to dispatch to a JSP to generate the HTML markup that consitutes the response to a request, a forward is what you need.

Upvotes: 1

Related Questions