Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Variable Length Argument List with Tomcat/JSP fails to compile.

Reply
Thread Tools

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

 
 
smm1@mail.com
Guest
Posts: n/a
 
      12-11-2006
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.

 
Reply With Quote
 
 
 
 
Juha Laiho
Guest
Posts: n/a
 
      12-11-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) 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-...#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)
 
Reply With Quote
 
 
 
 
smm1@mail.com
Guest
Posts: n/a
 
      12-12-2006
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:

> (E-Mail Removed) 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-...#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)


 
Reply With Quote
 
smm1@mail.com
Guest
Posts: n/a
 
      12-12-2006
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:

> (E-Mail Removed) 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-...#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)


 
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
Variable argument function as a parameter of a variable argument function AikidoGuy C Programming 11 11-21-2011 10:43 PM
Variable length argument list - 32 / 64 bit problem? Joakim Hove C Programming 5 03-14-2008 05:28 PM
Function pointers, variable argument functions calling other variable-argument functions (sort of) S?ren Gammelmark C Programming 1 01-07-2005 09:41 PM
How to pass variable argument list to another function w/ variable argument list? Ben Kial C Programming 1 11-15-2004 01:51 AM
transfering variable length argument list ANDERS FLODERUS C++ 1 12-20-2003 08:27 AM



Advertisments