What is the difference between getAttribute()
and getParameter()
methods within HttpServletRequest
class?
Java – Difference between getAttribute() and getParameter()
javajspservlets
Related Topic
- Java inner class and static nested class
- Java – the difference between public, protected, package-private and private in Java
- Java – a serialVersionUID and why should I use it
- Java – Difference between StringBuilder and StringBuffer
- Java – Difference between wait() and sleep()
- Java – Difference between HashMap, LinkedHashMap and TreeMap
- Java – What’s the difference between @Component, @Repository & @Service annotations in Spring
- Java – Why is subtracting these two times (in 1927) giving a strange result
Best Answer
getParameter()
returns http request parameters. Those passed from the client to the server. For examplehttp://example.com/servlet?parameter=1
. Can only returnString
getAttribute()
is for server-side usage only - you fill the request with attributes that you can use within the same request. For example - you set an attribute in a servlet, and read it from a JSP. Can be used for any object, not just string.