File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Elasticsearch in Action this week in the Big Data 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: 33

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

Joined: Oct 05, 2010
Posts: 163
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: 33

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: 163
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: 33

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...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Are getParameter and getAttribute interchangeable?