-
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
Code:
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.
WebApplication.jsp
Code:
<%@page import com.db4o.ObjectContainer%>
<html>
<head><title>Testing page</titile></head>
<body>
<jsp:useBean id="link" class = "Test.countryMethod" />
<%=link.getData() %>
</body>
</html>
-
<jsp:useBean id="link" scope="application" class = "Test.countryMethod" />
<jsp:setProperty name="link" property="*" />
plz try with this
Similar Threads
-
By n_yerramaneni in forum Java
Replies: 1
Last Post: 04-05-2005, 10:24 AM
-
Replies: 146
Last Post: 08-12-2002, 10:40 PM
-
Replies: 0
Last Post: 09-13-2001, 09:42 PM
-
By Mike in forum VB Classic
Replies: 2
Last Post: 04-24-2000, 03:30 PM
-
By Mike in forum VB Classic
Replies: 0
Last Post: 04-24-2000, 03:05 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks