It's not a secret anymore!
The moose likes Servlets and the fly likes difference between getParameter() and getAttribute() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "difference between getParameter() and getAttribute()" Watch "difference between getParameter() and getAttribute()" New topic

difference between getParameter() and getAttribute()

Basavaraj Reddy

Joined: Sep 19, 2010
Posts: 1
hi all,

can i know wat's the difference between getParameter() and getAttribute()
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63352

Did you check the javadocs?

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Welcome to JavaRanch
Malatesh Karabisti
Ranch Hand

Joined: Jul 28, 2010
Posts: 153

Hi Basavaraj,

Welcome to Java Ranch , check this. before posting your questions show some efforts if you still not able to find the answer million people are there to help you.

I hope this helps.
Jayavardhan geepi
Ranch Hand

Joined: Jul 21, 2010
Posts: 66
1 difference I know.

getParameter() always returns "String".
getAttribute() always returns type "Object". So, if you had setAttribute of type XXX, you have to cast it back while getting it.
dileep keely
Ranch Hand

Joined: Jun 28, 2010
Posts: 101
Give a try in knowing what exactly a parameter is and attribute ?that should solve your problem
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

Welcome to javaRanch.

SCJP6.0,My blog Ranchers from Delhi
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

Hello Basavaraj.

Are you studing web components? Do you have any material?

I would indicate to your Head First Web Components. It's a good book, you will lear those diferences.

Welcome to Javaranch!

[] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
eric totte

Joined: Aug 13, 2010
Posts: 10
Few differences..

Attributes can be used for communication between servlets. They store data in name value pairs, and can be get/set.
Parameters are bits of information from the client, they cannot be set.

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