只需将其设置为请求属性。
if (/* form is succesfully submitted */) {
request.setAttribute("success", true);
}
request.getRequestDispatcher("page.jsp").forward(request, response);
使用
JSTL
c:if
标记根据el表达式有条件地呈现内容。
<c:if test="${success}">
Your notification here.
</c:if>
如果您想在重定向后幸存,那么需要将其设置为会话属性:
if (/* form is succesfully submitted */) {
request.getSession().setAttribute("success", true);
}
response.sendRedirect("page.jsp");
使用
c:remove
在第一次显示后删除它,这样后续请求就不会受到影响:
<c:if test="${success}">
<c:remove var="success" scope="session" />
Your notification here.
</c:if>