Tomcat, jsp and primitive types

G

Guest

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
 
I

info

Try String.valueOf(int);. If just trying to get an int value in <%= %>
tags, try <%= int %>.

HTH

-- Kyle
 
G

Guest

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
 
A

AndrewTK

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.
 
C

Chris Smith

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.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top