What is the difference between getAttribute() and getParameter() in java?

0 votes
I am not able to get the difference between these two terminologies. If anybody can help?
Jun 29, 2018 in Java by Akrati
• 960 points
581 views

2 answers to this question.

0 votes

getParameter() -

  • getParameter will return the value of a parameter that was submitted by an HTML form or that was included in a query string
  • the return type for a parameter is a String
  • The Scope of the parameter is per individual request
getAttribute() -
  • getAttribute returns an object that you have set in the request, the only way you can use this is in conjunction with a RequestDispatcher. You use a RequestDispatcher to forward a request to another resource
  • The return type for attributes is an Object
  • Attribute is a server variable that exists within a specified scope application, available for the life of the entire application session, available for the life of the session request, only available for the life of the request page, available for the current JSP page only

answered Jun 29, 2018 by Perry
• 17,020 points
0 votes

getParameter() returns http request parameters. Those passed from the client to the server. 

For example - http://example.com/servlet?parameter=1. Can only return String

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.

answered Aug 28 by Sirajul
• 25,220 points

Related Questions In Java

0 votes
2 answers

What is the difference between Set and List in java?

LIST SET Duplicates YES NO Order Ordered Depends on Implementation Positional Access YES NO List is an ordered sequence ...READ MORE

answered Aug 14 in Java by Sirajul
• 25,220 points
105 views
0 votes
2 answers

What is the difference between Type List and type ArrayList in Java

By List, you actually tell, that your object ...READ MORE

answered Aug 28 in Java by Sirajul
• 25,220 points
72 views
0 votes
1 answer

What is the difference between getPath(), getAbsolutePath() and getCanonicalPath() in Java?

getPath() - returns a String which denotes the ...READ MORE

answered Jul 25, 2018 in Java by Mrunal
• 680 points
213 views
0 votes
2 answers

What is the difference between Map and HashMap in java?

The basic difference is : Map is ...READ MORE

answered Aug 28 in Java by Sirajul
• 25,220 points
157 views
+5 votes
3 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,380 points

edited Nov 6, 2018 by Omkar 8,054 views
0 votes
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,090 points
1,965 views
0 votes
1 answer

What are the differences between getText() and getAttribute() functions in Selenium WebDriver?

See, both are used to retrieve something ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,090 points
5,124 views
0 votes
1 answer

Selenium JARS(Java) missing from downloadable link

Nothing to worry about here. In the ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,090 points
492 views
0 votes
2 answers

How can I do url string decoding in java

We can use URLDecoder: URLDecoder.decode( url, "UTF-8" ); READ MORE

answered Dec 7, 2018 in Java by Sushmita
• 6,880 points
29 views
0 votes
2 answers

How to convert a java string into byte array

Try using String.getBytes(). It returns a byte[] ...READ MORE

answered Aug 22 in Java by Sirajul
• 25,220 points
52 views