File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes getAttribute VS getParameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "getAttribute VS getParameter" Watch "getAttribute VS getParameter" New topic

getAttribute VS getParameter

bobby chaurasia
Ranch Hand

Joined: Mar 30, 2002
Posts: 84
When would you use getParameter and when would you use getAttribute?
Nitzan Levi

Joined: Feb 19, 2003
Posts: 22
the get parameter is used when you want to get the http parameter's value that came from the user(via html)for example <input type='text' name='myParam'></input>
so when you do getParameter("myParam") you will get the value of that input field.
the get attribute is used when you want to get an attribute value that came from other servlet or JSP. that will happen only if the first servlet or JSP that got the request from the user activated the request.setAttribute("myAttribute","some value") and then activated the requestDispatcher("other servlet or jsp uri").forword(request,response)
hope that helps!

nitzan levi :-)
bobby chaurasia
Ranch Hand

Joined: Mar 30, 2002
Posts: 84
I agree. Here's the link:
subject: getAttribute VS getParameter
It's not a secret anymore!