This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Servlets and the fly likes Difference between getAttribute and getParameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Servlets
Bookmark "Difference between getAttribute and getParameter" Watch "Difference between getAttribute and getParameter" New topic

Difference between getAttribute and getParameter

navmn mn

Joined: Nov 30, 2004
Posts: 13

I am at present working on servlets, I am encountered an difficulty in differentiating b/w getAttribute and getParameter in servlets

I basicallly know
request.getAttribute("String") returns value in string

request.getParameter("String") returns an Object :roll:
I did not understand what type of object it returns

Thanks in advance
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

You've got it backwards.

GetParameter returns a String. It's what you use to retrieve form parameters from an HTTP post.

getAttribute(String) and setAttribute(String, Object) are what you use to bind object variables to a scope (request, session, or context) and retrieve them from another servlet or JSP.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Have you checked out Aspose?
subject: Difference between getAttribute and getParameter
It's not a secret anymore!