Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Are getParameter and getAttribute interchangeable?

 
mohammad shadab
Ranch Hand
Posts: 52
Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"can we use getParameter instead of getAttribute in servlet/jsp ???"
 
Ahsan Bagwan
Ranch Hand
Posts: 254
1
Java MySQL Database Ubuntu
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your question is a bit vague.

Both of these methods have different purposes. If you want to submit a form or send a GET request to the server, you will always need a 'getParameter()' invoked on a request object to obtain form control values.

When you desire to use a value across subsequent page/many pages in an application use 'getAttribute()' and 'setAttribute()' method. For instance if you want to forward a message to a JSP from a servlet you place that message in the request scoped variable using setAttribute().

 
mohammad shadab
Ranch Hand
Posts: 52
Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahsan Bagwan wrote:Your question is a bit vague.

Both of these methods have different purposes. If you want to submit a form or send a GET request to the server, you will always need a 'getParameter()' invoked on a request object to obtain form control values.

When you desire to use a value across subsequent page/many pages in an application use 'getAttribute()' and 'setAttribute()' method. For instance if you want to forward a message to a JSP from a servlet you place that message in the request scoped variable using setAttribute().


as you said "If you want to submit a form or send a GET request to the server, you will always need a 'getParameter()" .is there any thing different for POST request???
 
Ahsan Bagwan
Ranch Hand
Posts: 254
1
Java MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. I indeed meant POST when I referred to form submission (in the context that you want to change server state (like inserting employee record in db)).
 
mohammad shadab
Ranch Hand
Posts: 52
Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahsan Bagwan wrote:No. I indeed meant POST when I referred to form submission (in the context that you want to change server state (like inserting employee record in db)).
okay thank you ahsan bro...
 
This will take every ounce of my mental strength! All for a tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!