tags:

views:

15

answers:

1

I have HTML code in the jsp page that I want it to be displayed only after the user submits data and get redirected to this page. So I have to set a success flag as a parameter in the link like:

http://site.com/page?success=true

Not sending in the request because it will be lost since I am redirecting I don't want to send it in the link as a parameter and I am thinking of another way and ideas how to send it? So the link will be:

http://site.com/page

and I can display the the html code?

+1  A: 

Just set it as a request attribtue.

if (/* form is succesfully submitted */) {
    request.setAttribute("success", true);
}
request.getRequestDispatcher("page.jsp").forward(request, response);

Use JSTL c:if tag to conditionally render content based on EL expression.

<c:if test="${success}">
    Your notification here.
</c:if>

If you want to survive the redirects, then you need to set it as session attribtue instead:

if (/* form is succesfully submitted */) {
    request.getSession().setAttribute("success", true);
}
response.sendRedirect("page.jsp");

Use c:remove remove it after first display so that the subsequent requests won't be affected:

<c:if test="${success}">
    <c:remove var="success" scope="session" />
    Your notification here.
</c:if>
BalusC