File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Difference between getAttribute(string) and getParameter(String)" Watch "Difference between getAttribute(string) and getParameter(String)" New topic

Difference between getAttribute(string) and getParameter(String)

praveen kumar gowda

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

I agree. Here's the link:
subject: Difference between getAttribute(string) and getParameter(String)
It's not a secret anymore!