jQuery in Action, 3rd edition
The moose likes Servlets and the fly likes Are getParameter and getAttribute interchangeable? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Are getParameter and getAttribute interchangeable?" Watch "Are getParameter and getAttribute interchangeable?" New topic
Author

Are getParameter and getAttribute interchangeable?

mohammad shadab
Ranch Hand

Joined: Jul 09, 2013
Posts: 34

"can we use getParameter instead of getAttribute in servlet/jsp ???"
Ahsan Bagwan
Ranch Hand

Joined: Oct 05, 2010
Posts: 219

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

Joined: Jul 09, 2013
Posts: 34

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

Joined: Oct 05, 2010
Posts: 219

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

Joined: Jul 09, 2013
Posts: 34

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...
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Are getParameter and getAttribute interchangeable?
 
jQuery in Action, 3rd edition