'jstl variable is not even removed after setting it to null or using the c:remove

im trying to remove a session variable using the c:remove or c:set to ${null} but it did not work. I'm expecting the variable will be removed once I refresh the page but it didn't.

my servlet will set a session attribute to give a 'succcess' message once pet details are registered. my jsp page will c:choose if the session is not null, then display a success box, followed by removing the session using c:remove or c:set to null. Otherwise, the success box will not be displayed if the session variable is null.

however, once I refreshed the page, the success box is still there.

my servlet : (PetRegisterController)

protected void doPost(HttpServletRequest request, HttpServletResponse response) 
        throws ServletException, IOException 
{
    HttpSession session = request.getSession();
    
    //retrieving ownerID
    OwnerModel ownerbean =(OwnerModel)request.getSession().getAttribute("ownermodel");
    int ownerID = ownerbean.getUserID();
    
    //retriving all necessary pet details for registration
    String petname = request.getParameter("petname");
    String petGender = request.getParameter("gender");
    String petType = request.getParameter("pettype");
    String furtype = request.getParameter("furtype");
    String ageClass = request.getParameter("ageclass");
    
    //store new pet details into petmodel bean
    PetModel petbean = new PetModel();
    
    petbean.setPetName(petname);
    petbean.setPetType(petType);
    petbean.setAgeClass(ageClass);
    petbean.setFurType(furtype);
    petbean.setGender(petGender);
    petbean.setOwnerID(ownerID);
    
    //send petbean to PetRegisterDAO
    //PetRegisterDAO.registerPet(petbean);
    
    if(petbean != null)
    {
        String message = "successfully registered";
        session.setAttribute("success",message);
        response.sendRedirect("petregister.jsp");
    }


}

my jsp page:

<c:set var="message" value="${success}" scope="session" />

<c:choose>

            <c:when test="${not empty message}">
                
                <div id="successbox">
                <div class="alert alert-success" role="alert">successfully registered your pet!</div>
                </div>
                
                <c:set var="message" value="${null}"/>
                <c:remove var="message"/>
                
            </c:when>

            <c:when test="${empty message}">
                 <p>message is empty</p>
             </c:when>
 
        </c:choose>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source