Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Tomcat, jsp and primitive types

Reply
Thread Tools

Tomcat, jsp and primitive types

 
 
barth_no_spam@yahoo.fr
Guest
Posts: n/a
 
      03-27-2006
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

 
Reply With Quote
 
 
 
 
info@hmdproducts.com
Guest
Posts: n/a
 
      03-27-2006
Try String.valueOf(int);. If just trying to get an int value in <%= %>
tags, try <%= int %>.

HTH

-- Kyle

 
Reply With Quote
 
 
 
 
barth_no_spam@yahoo.fr
Guest
Posts: n/a
 
      03-27-2006
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

 
Reply With Quote
 
AndrewTK
Guest
Posts: n/a
 
      03-27-2006
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.

 
Reply With Quote
 
Chris Smith
Guest
Posts: n/a
 
      03-27-2006
<> wrote:
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Default primitive values from primitive Class<?> object. Daniel Pitts Java 7 10-23-2008 04:30 PM
Enums and returning primitive types Wannabe ASP .Net 2 08-28-2008 10:40 PM
JNI: passing Objects containing non-primitive types back and forth bernd Java 1 06-13-2008 08:31 PM
Primitive vs. non-primitive l-value richardclay09@yahoo.co.uk C++ 7 05-09-2005 02:52 PM
Collections API for primitive types =?ISO-8859-1?Q?S=F8ren_Bak?= Java 0 08-27-2003 06:59 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57