How to instantiate a .class from a JSP?

Hi,

probably it's a simple problem, byt I'm new in JSP and I couldn't work it out.

I'm converting a SSJS Netscape Application to JSP. My needing is to write a Java .class containing only static methods, to call them from the JSP pages.

For trying, I wrote a simple class that I call from a JSP page, but I get this error:

Error: 500

Location: /JSP24H/cap01/Simple2.jsp

Internal Servlet Error:

org.apache.jasper.JasperException: Unable to compile class for

JSPC:\tomcat\work\localhost_8080%2FJSP24H\_0002fcap_00030_00031_0002fSimple_00032_0002ejspSimple2_jsp_0.java:80:

Incompatible type for =. Can't convert void to java.lang.String.

v = GenFunction.messaggio();

^

This is the JSP instantiating the Java class:

<HTML>

<HEAD><TITLE>A Simple JSP</TITLE></HEAD>

<BODY>

<FONT COLOR="blue" FACE="Trebuchet">

<CENTER>

<%@ page import = "GenFunction" %>

<% out.println("My name is Charly !" + "<br>"); %>

<%

String v = " ";

v = GenFunction.messaggio();

out.println( v );

%>

</CENTER>

</FONT>

</BODY>

</HTML>

And this is the class instantiated from JSP:

public class GenFunction {

public static void main (String args[]) {

}

public static String messaggio() {

String a;

a = " Hello world !";

return a;

}

}

In order to be sure about what I'm doing, I opened a DOS window and I called the class within the following:

public class call_Class {

public static void main (String args[])

{

String v;

GenFunction x = new GenFunction();

v = x.messaggio();

System.out.println(v);

}

}

When I instantiate the class from DOS it's all right, why not from JSP. It seems to be returning a void value (I tried with casting too but without success).

Thanks !

[2103 byte] By [e-karlo] at [2007-9-26 6:56:04]
# 1
Do you have multiple versions of classes in the server CLASSPATH somehwhere? If you have changed the class, and not bounced the server, try bouncing the server(may be using cached class)-Mak
makarand_k at 2007-7-1 16:27:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...