Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

does request.getParameter return only String

 
anarkali perera
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am getting age as a nt from a form.
but when i use
int age=request.getParameter("age");
as this it gives error.
i need to get age as a int.can't i do this directly without using any conversion?
 
Vijitha Kumara
Bartender
Posts: 3953
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You get all the request parameters in the form of "String", so you have to convert them yourself.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HTTP forms send strings *only*.

If you look at the data on the wire there is zero information contained in a normal form submission to indicate what the type of the data is. HTML/HTTP have no concept of data types.
 
azhar jodatti
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its right.. i will return only string and null if parameter wont found..
so be carefull while casting it to numeric data type because it will throw NullPointerException if you try to cast null value....
 
Anil kumar Sakala
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Data comes to user as HttpResponse which is nothing but a string of data.
It is our responsibility to convert this to java data type before using it .

If you are using frameworks like Struts2 , frame work (params interceptor) take the responsibility of converting it to java data type
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!