Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Are getParameter and getAttribute interchangeable?

 
mohammad shadab
Ranch Hand
Posts: 44
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: 252
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: 44
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: 252
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: 44
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic