• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

does request.getParameter return only String

 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You get all the request parameters in the form of "String", so you have to convert them yourself.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic