removeAttribute() Method Of The Request Object
This section introduces for the method removeAttribute() of the request object. This method removes the attribute. This method takes a string type parameter i.e. the attribute name that has to be removed. After applying this method you can't access the attribute. If you specify the method for getting the value of the attribute what has removed, you will get the null value.
In this section, you will see more about the removeAttribute() method of the request object in JSP by learning through the provided description and the JSP code of the example. You can understand very efficiently the JSP code of the example.
Here is the JSP code of the RemoveAttributeMethod.jsp file:
<% request.setAttribute("UName", "chandan"); request.setAttribute("Password", "chand"); String pageName = "RemoveAttributeMethod1.jsp"; RequestDispatcher requestDispatcher = request.getRequestDispatcher (pageName); if(requestDispatcher != null){ requestDispatcher.forward(request, response); } %>
Here is the JSP code of the RemoveAttributeMethod1.jsp file:
<b> <% out.println("User Name: " + request.getAttribute("UName") + "<br/>"); out.println("Password: " + request.getAttribute("Password") + "<br/>"); request.removeAttribute("Password"); out.println("Your name: " + request.getAttribute("UName") + "<br/>"); out.println("Your password: "); if(request.getAttribute("Password") == null) out.println("\'Password\' attribute is removed."); else out.println(request.getAttribute("Password")); %></b>
Output for the both examples: