This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes Difference between getAttribute(string) and getParameter(String) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Difference between getAttribute(string) and getParameter(String)" Watch "Difference between getAttribute(string) and getParameter(String)" New topic
Author

Difference between getAttribute(string) and getParameter(String)

praveen kumar gowda
Greenhorn

Joined: Feb 20, 2012
Posts: 23
hi guys,
i come to know how get Parameter method works.....In that,

1)when we submit the form without fields value(empty form) ,will the value is null or empty?

please explain me about get Attribute method..i am not clearing of this..
Sabarish Venkat
Ranch Hand

Joined: Jan 18, 2012
Posts: 136

1. When you use getParameter() method and send it as empty you will get Null pointer exception since null values are retrived.

And the difference between getParameter() and getAttribute() is ,In getParameter you can retrive the values of the form.

Say you have


In the above code you can see the name="user1" this the key for us to take the user name type by the user. In next page you can get it as



Now you will get the user name typed by user.


For getAttribute(),

If you have a string value in a page and you want to take it to next page that time we use getAttribute(). It will get the value from previous page as session

Say ,



Now in next page you will get the session as,



This is the difference ... Check the bold words for exact difference to say in one word


 
Don't get me started about those stupid light bulbs.
 
subject: Difference between getAttribute(string) and getParameter(String)
 
Similar Threads
skipping JSF validation for reset event
need help urgently
Checkbox/Multibox validation in Struts
Writing an Empty Line in a File....
numberformatexception