• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

parameter and attribute in servlet

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All..

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

Thanks,
Sailaja
 
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might be interested in this article

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


- Naseem
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Ranch Hand
Posts: 401
Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 401
Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you mean HTTP requests are only through client side?
 
See ya later boys, I think I'm in love. Oh wait, she's just a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic