Using Parameters in Post Redirect Get...

.. instead of keeping the data in Application Scope.

Improved the previous example a little. What has been changed can be seen here:

Now I am using param in index.jsp:
<div>
    <c:if test="${param.username ne null}">
        Hello ${param.username}
    </c:if>
</div>

And in the Servlet I have:
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    req.getRequestDispatcher("index.jsp").forward(req, resp);
}
 
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    final String username = req.getParameter("username");
    final String contextPath = getServletContext().getContextPath();
    resp.sendRedirect(contextPath + "?username=" + username);
}

Behaviour is still the same..