Hello,
I am trying to use Tomcat. I get errors in my jsp if i use primitive
types, int per instance :
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 61 in the jsp file: /WEB-INF/jsp/example.jsp
Generated servlet error:
Cannot invoke toString() on the primitive type int
I understand this error, but I am surprised that tomcat could not solve
it by itself as I have never had problems when using OC4J for example.
Or do I have to configure something ?
Thanks in advance, best regards
Barth
info@hmdproducts.com - 27 Mar 2006 12:42 GMT
Try String.valueOf(int);. If just trying to get an int value in <%= %>
tags, try <%= int %>.
HTH
-- Kyle
barth_no_spam@yahoo.fr - 27 Mar 2006 14:18 GMT
I use String.valueOf(int) but it seems to me that it's quite 'heavy'...
And I have to change it in a lot of pages.
By the way, the <%= int %> doesn't work.
Thanks for your ideas
Barth
Chris Smith - 27 Mar 2006 16:48 GMT
> By the way, the <%= int %> doesn't work.
By "int", it is meant that you should place the int variable there. For
example:
<%= 6 %>
Yes, that does work. If it doesn't appear to work for you, then your
problem must lie elsewhere. Please post a small self-contained bit of
sample code that fails in the way you describe, and more people will be
able to help you.

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
AndrewTK - 27 Mar 2006 14:22 GMT
As a general rule primitives are not objects - they're primitives. They
have therfore no methods or attributes, and are not int the object
tree. This tends to be the rule for all programming languages that
differentiate primitives and objects
If you have previously been calling methods from primitives which your
compiler has interpreted... it's bad style (you end up with bad code on
forums like this - apart from which it's no longer Java) and ambiguous
at best. Compilers should never make assupmtions on code.
String.valueOf(int) works
What also works is String str = ""+int;
In Java, primitives have object counterparts however. If you really
want to be using methods, use
Integer int_obj = new Integer( int )
However, you can not do int_obj + int_obj (you'll probably just end up
concatenating their string values, if anything at all) Any other
athematical operator will throw an error.