• Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp interger values

 
Atul Dusara
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got a problem where I'm trying to get JSP to get an integer from a HTML form. i've tried declaring it as an int and using getInt to find it, but it doesn't work. and neither does getParameter. The reason why I need to use an integer is so that I can do a calculation further on, and JSP won't allow me to do if it is s string.
This is the code
int debits = request.getParameter("amount");
The error I am getting is.
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 53 in the jsp file: /virtual_bank/virtual_cheque.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\Tomcat 4.1\work\Standalone\localhost\_\virtual_bank\virtual_cheque_jsp.java:126: incompatible types
found : java.lang.String
required: int
int debits = request.getParameter("amount");
^
If anyone knows what I'm doin wrong, then I would to know your ideas.
Thanks in advance.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
request parameters are always String objects - obviously you need to convert to int - try looking at the "wrapper" class for int - Integer. There you will find methods for parsing a String into an int.
Bill
 
Joe Broderick
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to have your variable as a string, then you could parse it to an integer if you want.
 
Sean Clarke
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:
int debits = Integer.parseInt(request.getParameter("amount"));
It will throw an exception if the amount is non-numeric though.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!