How to call java method in jsp file?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: How to call java method in jsp file?

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Posts
    19

    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>

  2. #2
    Join Date
    Dec 2008
    Posts
    1
    <jsp:useBean id="link" scope="application" class = "Test.countryMethod" />
    <jsp:setProperty name="link" property="*" />


    plz try with this

Similar Threads

  1. how to call ProC or C exe file from Java program
    By n_yerramaneni in forum Java
    Replies: 1
    Last Post: 04-05-2005, 11:24 AM
  2. How long before the next version??
    By _CAG in forum .NET
    Replies: 146
    Last Post: 08-12-2002, 11:40 PM
  3. call c file form java
    By sambhu in forum Java
    Replies: 0
    Last Post: 09-13-2001, 10:42 PM
  4. NetUserEnum Api
    By Mike in forum VB Classic
    Replies: 2
    Last Post: 04-24-2000, 04:30 PM
  5. NetUserEnum Api
    By Mike in forum VB Classic
    Replies: 0
    Last Post: 04-24-2000, 04: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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center