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;
public class countryMethod {
public final static String filename = "C:\\TestStore.yap";
public String record;
public int value;
public String cName1;
private static ObjectContainer db = Db4o.openFile(filename);
public static void 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.
<%@page import com.db4o.ObjectContainer%>
<html>
<head><title>Testing page</titile></head>
<body>
<jsp:useBean id="link" class = "Test.countryMethod" />
<%=link.getData() %>
</body>
</html>