Forums Register Login

does request.getParameter return only String

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
You get all the request parameters in the form of "String", so you have to convert them yourself.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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....
+Pie Number of slices to send: Send
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
expectation is the root of all heartache - shakespeare. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3032 times.
Similar Threads
How to stop the struts parser to parse the request parameters temporarily?
java.lang.IllegalStateException in Servlet
Url Rewriting
ResultSet.updateString() , updateInt() are not updating values
jsp age verification code
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 21:30:29.