Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

Tomcat, jsp and primitive types

Thread view: 
barth_no_spam@yahoo.fr - 27 Mar 2006 10:28 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.