aspose file tools*
The moose likes Servlets and the fly likes parameter and attribute in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "parameter and attribute in servlet" Watch "parameter and attribute in servlet" New topic
Author

parameter and attribute in servlet

Mahesh Barik
Greenhorn

Joined: Aug 14, 2006
Posts: 15
1.what is the difference between parameter and attribute in servlet?


sometime we use getParameter() and at other time getAttribute() where to use which one?

can you please suggest me?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Parameters are data submitted from the client as part of an HTTP post or get.

Attributes, also termed scoped variables, are set on the server by server-side code.
[ August 23, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
chloe wong
Greenhorn

Joined: Aug 02, 2006
Posts: 17
Parameter is the one when you use to direct to another page. A good example will be http://localhost/a.do?name=blablabla.
Attribute is the one a programmer set in the java action. For instance, if you're doing a struts framework, in ActionA you'll write AactionForm.getSession().setAttribute("",); In ActionB, you'll write BactionForm.getSession().getAttribute(""); to get the value.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

amateur83,
Welcome to JavaRanch!

We're pleased to have you here with us in the servlets forum, but there
are a few rules that need to be followed, and one is that proper names are
required. Please take a look at the
JavaRanch Naming Policy and
adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

You can change it here


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Sailaja Chowdary
Greenhorn

Joined: Aug 08, 2006
Posts: 5
Hi All..

Can anyone make it more clear with an example on the same topic.

Thanks,
Sailaja
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
You might be interested in this article

Purchase some book on servlet. Core servlet and jsp is good to start with.


- Naseem


Asking Smart Questions FAQ - How To Put Your Code In Code Tags
Wei Geng
Greenhorn

Joined: Dec 10, 2004
Posts: 28
In my point of view, the differences between Paramter and Attribute are:
1. Parameter is used to transmit the information to another component (such as Servlet, JSP); Attribute is to share the information Object with the components in the certain scope (such as Page, Request, Session, Application).
2. Parameter can only transmit the value of String type; Attribute can transmit the value of any Object with the class casting.
arun krishnamurthy
Greenhorn

Joined: Aug 30, 2006
Posts: 6
In my point of view, the differences between Paramter and Attribute are:
Take example of context object
1.Parameter are going to set in web.xml.The value of this parameter are constant.You have to redeploy the in order to change the value of the Parameter
2. Attributes can set and get.And also it can change the value.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Originally posted by arun krishnamurthy:

1.Parameter are going to set in web.xml.


That's a context parameter and is a completely different concept than a request parameter, which is what I believe the original poster was asking about.
[ August 30, 2006: Message edited by: Bear Bibeault ]
Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

Originally posted by Bear Bibeault:


That's a context parameter and is a completely different concept than a request parameter, which is what I believe the original poster was asking about.

[ August 30, 2006: Message edited by: Bear Bibeault ]


In web.xml file we can declare both context or application specific and servletconfig or aperticular servlet specific parameters but Mr Ben may know why you have only explined about context parameter.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

This is getting off-topic. Be they context parameters or init parameters for a servlet, declarations in the web.xml are a completely separate concept from request parameters.

Back on subject please.
Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

Hi,

According to Head First servlets and JSP -- Attiribute is an object which is set on in one of the three servlet APIs , ServeltRequest, HttpSession, ServletContext.
vineet kaur
Greenhorn

Joined: May 22, 2009
Posts: 2


someone says that A parameter is a form field name/value pair passed from theHTML side of the world and
An attribute is a java object name/ value pair passed only through JSP or servlet but not from HTML page.
What does that mean actually?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

It means that "attributes", properly termed scoped variables, are server-side concepts and do not participate in HTTP requests, and never are passed to or from the client.
Birla Murugesan
Ranch Hand

Joined: Nov 25, 2008
Posts: 66

Parameter:

while sending request to server side java file at client side,
we are forming that parameter which was send along with request
so parameter is something like input given to requested java file
Its value is a String.

Attribute:

It's a key/value pair which is set at server side java file which redirected to another java or jsp
so the redirected java would get that attribute by using getAttribute.
Its value is a object.
the redirection is happen inside the server side,so there is no need to send the value through parameter.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Birla Murugesan wrote:
Attribute:

It's a key/value pair which is set at server side java file which redirected to another java or jsp
so the redirected java would get that attribute by using getAttribute.
Its value is a object.
the redirection is happen inside the server side,so there is no need to send the value through parameter.

Not quite correct. Redirects are not restricted to the server, they are sent to the client and a new request is initiated. So whether the scoped variable (the correct term for "attribute") survives the redirect depends upon which scope it is placed in.

Perhaps you are confusing a redirect with a forward?
Birla Murugesan
Ranch Hand

Joined: Nov 25, 2008
Posts: 66
Bear Bibeault wrote:
Not quite correct. Redirects are not restricted to the server, they are sent to the client and a new request is initiated. So whether the scoped variable (the correct term for "attribute") survives the redirect depends upon which scope it is placed in.

Perhaps you are confusing a redirect with a forward?



I am not saying redirection only happens inside the serverside.

what i am saying is,if redirection happens within the serverside,there is no need to send values through parameter to redirected page,instead of we can use Attribute to do this process
But we can use attribute at client side itself

Hope you understand.


vineet kaur
Greenhorn

Joined: May 22, 2009
Posts: 2
you mean HTTP requests are only through client side?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: parameter and attribute in servlet