Home Jsp removeAttribute() Method Of The Request Object
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

removeAttribute() Method Of The Request Object

Advertisement
This section introduces for the method removeAttribute() of the request object.

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:

Download the RemoveAttributeMethod.jsp file.

Download the RemoveAttributeMethod1.jsp file.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 9, 2008

Related Tutorials

Ask Questions?    Discuss: removeAttribute() Method Of The Request Object   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com