• Post Reply Bookmark Topic Watch Topic
  • New Topic

what is the attribute in servlet ?

 
vidya vani
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!!
Iwas bit confused about the scope of attributes while using them.what is the difference between getParameter() and getAttrbibute() in servlet,jsp.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65529
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getAtribute() fetches a scoped variable placed into the target scope. getParameter() returns the value of a request parameter that was submitted as part of a form or on the query string of the URL.
 
Lave Kulshreshtha
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getParameter is used to read the HTML/JSP field values (text box, radio button etc) and getParameter returns a String.

getAttribute is used get object available in request, session and servletContext. getAttribute returns an Object.

-Lave

Originally posted by vidya vani:
Hello!!
Iwas bit confused about the scope of attributes while using them.what is the difference between getParameter() and getAttrbibute() in servlet,jsp.
 
santosh kothapalli
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
putting in simple words
use getParameter() when the request /form is submitted to the server where as getAttribute() can be used at page,sesion and application level

-if a variable is set at request level using setAttribute that can be accessed by getAttribute only in the immediate submitted page
-if a variable is set at session level using setAttribute that can be accessed by getAttribute throught the session availability
-if a variable is set at context level using setAttribute that can be accessed by getAttribute through out the application by all the users
 
ssjava
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi...
get parameter is used to get the value for one jsp page to other.
But,getAttribute is related to httpsession...

siva
[ January 19, 2008: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65529
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by siva prasad java:

But,getAttribute is related to httpsession...

This is not correct. Scoped variables (aka "attributes") can exist in one of four scopes, including the session.
[ January 20, 2008: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65529
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"siva prasad java", please check your private messages for an important administrative matter.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by siva prasad java:
get parameter is used to get the value for one jsp page to other.


This isn't entirely accurate either.
The request.getParameter method is used to retrieve form and query string parameters. In other words, parameters are used to pass values from the browser to the server.

By using hidden input fields, you can use parameters to pass values from one JSP or servlet to another but the primary purpose is to gather user input from the client.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!