How to call java method in jsp file?

can anyone guide me or teach me how can i call the java method into the jsp file? do i need a main method to call it in? or just call the method that i need 2 use only?

below is the coding that i did. one is java and another one is jsp. hope that someone can help me on it. Thanks!!!! Really appreciate it.

Country Method.java

package Test;

import java.io.File;

import com.db4o.*;

import com.db4o.ObjectContainer;

import com.db4o.ObjectSet;

publicclass countryMethod{

publicfinalstatic String filename ="C:\\TestStore.yap";

public String record;

publicint value;

public String cName1;

privatestatic ObjectContainer db = Db4o.openFile(filename);

publicstaticvoid storeData(){

//Delete existing data file

new File(filename).delete();

//Open Database

db = Db4o.openFile(filename);

//Add value into database

Country c1 =new Country(100,"Malaysia");

Country c2 =new Country(200,"Thailand");

Country c3 =new Country(300,"Sing");

Country c4 =new Country(400,"Japan");

Country c5 =new Country(500,"Indian");

db.set(c1);

db.set(c2);

db.set(c3);

db.set(c4);

db.set(c5);

System.out.println("abc");

}

public String getData(){

String str ="";

try{

//open database

ObjectContainer db = Db4o.openFile(filename);

//Create empty object

Country country =new Country(0,null);

//Object dataset

ObjectSet result = db.get(country);

//System.out.println(result.size());

while(result.hasNext()){

Country a = (Country)result.next();

record = a.getName();

value = a.getValue();

str = str +" | "+ value;

//System.out.println(str);

//System.out.println(a.getValue());

}

}catch(Exception s){

s.printStackTrace();

}

str = str +" | "+ record;

return str;

}

/*public int getValue(){

return value;

}*/

}

and the jsp.

<%@pageimport com.db4o.ObjectContainer%>

<html>

<head><title>Testing page</titile></head>

<body>

<jsp:useBean id="link"class ="Test.countryMethod" />

<%=link.getData() %>

</body>

</html>

[4430 byte] By [erickha] at [2007-10-3 7:27:45]
# 1

Modify the jsp as below, you might also want to make the getData() method static:

<%@page import com.db4o.ObjectContainer%>

<%@page import="Test.countryMethod "%>

<html>

<head><title>Testing page</titile></head>

<body>

<%

out.println(countryMethod.getData());

%>

</body>

</html>

asabbia at 2007-7-15 2:26:48 > top of Java-index,Desktop,Developing for the Desktop...
# 2
Try the following forum (about JSP technology) http://forum.java.sun.com/forum.jspa?forumID=45
UncleSAMa at 2007-7-15 2:26:48 > top of Java-index,Desktop,Developing for the Desktop...