Variable Length Argument List with Tomcat/JSP fails to compile.

Discussion in 'Java' started by smm1@mail.com, Dec 11, 2006.

  1. Guest

    I have a method that takes a variable length arg list:
    "testmethod(int...in)".

    Using this method from a 'regular' java program (i.e. via 'main') works
    just fine, but when invoked from Tomcat/JSP I get an error:

    "Generated servlet error:
    The method testmethod(int[]) in the type testclass is not applicable
    for the arguments (int, int, int)"

    The java:

    package testpackage ;
    public class testclass {
    public static int testmethod(int... in) {
    return in[1] ;
    }
    public static void main(String[] args) {
    System.out.println(testmethod(1,2,3)) ;
    }
    }

    The JSP:
    <%@ page import="testpackage.testclass.*" %>
    <%
    out.println(testpackage.testclass.testmethod(1,2,3));
    %>

    I'm using Tomcat 5.5.12 and java 1.5.0_06.

    Any ideas on how I can get this JSP to compile? Thanks for any help.
    , Dec 11, 2006
    #1
    1. Advertising

  2. Juha Laiho Guest

    said:
    >I have a method that takes a variable length arg list:
    >"testmethod(int...in)".


    Weren't vararg methods implemented in Java 1.5? If so, there is your
    problem. By default the JSP compiler still in Tomcat 5.5 handles
    Java 1.4.

    This can be changed with Tomcat configuration for the Jasper servlet; see:
    http://tomcat.apache.org/tomcat-5.5-doc/jasper-howto.html#Configuration
    --
    Wolf a.k.a. Juha Laiho Espoo, Finland
    (GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
    PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
    "...cancel my subscription to the resurrection!" (Jim Morrison)
    Juha Laiho, Dec 11, 2006
    #2
    1. Advertising

  3. Guest

    Juha-
    Thanks for pointing me in the right direction.

    Eventually I got it going by downloading current copies of:
    - jasper-compiler-jdt.jar
    - jasper-compiler.jar
    - jasper-runtime.jar
    This solves the problem, with no config required.

    But before, that I found another solution:

    1. Adding the following lines to conf/web.xml
    <servlet>
    <servlet-name>jsp</servlet-name>

    <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>

    <init-param>
    <param-name>xpoweredBy</param-name>
    <param-value>false</param-value>
    </init-param>
    <!-- added these lines...
    <init-param>
    <param-name>compilerTargetVM</param-name>
    <param-value>1.5</param-value>
    </init-param>
    <init-param>
    <param-name>compilerSourceVM</param-name>
    <param-value>1.5</param-value>
    </init-param>
    ....
    This by itself does not solve the problem.

    2. remove common/lib/jasper-compiler-jdt.jar

    3. Download the current ant release from
    http://ant.apache.org/bindownload.cgi and copy ant.jar to
    common/lib/ant.jar

    4. Copy tools.jar from $JAVA_HOME/lib to common/lib


    Juha Laiho wrote:

    > said:
    > >I have a method that takes a variable length arg list:
    > >"testmethod(int...in)".

    >
    > Weren't vararg methods implemented in Java 1.5? If so, there is your
    > problem. By default the JSP compiler still in Tomcat 5.5 handles
    > Java 1.4.
    >
    > This can be changed with Tomcat configuration for the Jasper servlet; see:
    > http://tomcat.apache.org/tomcat-5.5-doc/jasper-howto.html#Configuration
    > --
    > Wolf a.k.a. Juha Laiho Espoo, Finland
    > (GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
    > PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
    > "...cancel my subscription to the resurrection!" (Jim Morrison)
    , Dec 12, 2006
    #3
  4. Guest

    Juha-
    Thanks for pointing me in the right direction.

    Eventually I got it going by downloading current copies of:
    - jasper-compiler-jdt.jar
    - jasper-compiler.jar
    - jasper-runtime.jar
    This solves the problem, with no config required.

    But before, that I found another solution:

    1. Adding the following lines to conf/web.xml
    <servlet>
    <servlet-name>jsp</servlet-name>

    <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>

    <init-param>
    <param-name>xpoweredBy</param-name>
    <param-value>false</param-value>
    </init-param>
    <!-- added these lines...
    <init-param>
    <param-name>compilerTargetVM</param-name>
    <param-value>1.5</param-value>
    </init-param>
    <init-param>
    <param-name>compilerSourceVM</param-name>
    <param-value>1.5</param-value>
    </init-param>
    ....
    This by itself does not solve the problem.

    2. remove common/lib/jasper-compiler-jdt.jar

    3. Download the current ant release from
    http://ant.apache.org/bindownload.cgi and copy ant.jar to
    common/lib/ant.jar

    4. Copy tools.jar from $JAVA_HOME/lib to common/lib


    Juha Laiho wrote:

    > said:
    > >I have a method that takes a variable length arg list:
    > >"testmethod(int...in)".

    >
    > Weren't vararg methods implemented in Java 1.5? If so, there is your
    > problem. By default the JSP compiler still in Tomcat 5.5 handles
    > Java 1.4.
    >
    > This can be changed with Tomcat configuration for the Jasper servlet; see:
    > http://tomcat.apache.org/tomcat-5.5-doc/jasper-howto.html#Configuration
    > --
    > Wolf a.k.a. Juha Laiho Espoo, Finland
    > (GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
    > PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
    > "...cancel my subscription to the resurrection!" (Jim Morrison)
    , Dec 12, 2006
    #4
    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. ANDERS FLODERUS
    Replies:
    1
    Views:
    372
    Rob Williscroft
    Dec 20, 2003
  2. Ben Kial
    Replies:
    1
    Views:
    643
    Eric Enright
    Nov 15, 2004
  3. S?ren Gammelmark
    Replies:
    1
    Views:
    1,879
    Eric Sosman
    Jan 7, 2005
  4. Joakim Hove
    Replies:
    5
    Views:
    517
    Joakim Hove
    Mar 14, 2008
  5. Keve Nagy
    Replies:
    4
    Views:
    2,089
    Keve Nagy
    Apr 4, 2009
Loading...

Share This Page