Tomcat, jsp and primitive types

Discussion in 'Java' started by barth_no_spam@yahoo.fr, Mar 27, 2006.

  1. 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
    , Mar 27, 2006
    #1
    1. Advertising

  2. Guest

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

    HTH

    -- Kyle
    , Mar 27, 2006
    #2
    1. Advertising

  3. 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
    , Mar 27, 2006
    #3
  4. AndrewTK Guest

    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.
    AndrewTK, Mar 27, 2006
    #4
  5. Chris Smith Guest

    <> 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
    Chris Smith, Mar 27, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-1?Q?S=F8ren_Bak?=

    Collections API for primitive types

    =?ISO-8859-1?Q?S=F8ren_Bak?=, Aug 27, 2003, in forum: Java
    Replies:
    0
    Views:
    391
    =?ISO-8859-1?Q?S=F8ren_Bak?=
    Aug 27, 2003
  2. Replies:
    7
    Views:
    580
    Victor Bazarov
    May 9, 2005
  3. bernd
    Replies:
    1
    Views:
    764
    bernd
    Jun 13, 2008
  4. Wannabe

    Enums and returning primitive types

    Wannabe, Aug 28, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    288
    Wannabe
    Aug 28, 2008
  5. Daniel Pitts
    Replies:
    7
    Views:
    455
Loading...

Share This Page