Search code examples
javajspstruts2ognlstruts-tags

Calling bean method on jsp


I'm trying to call a method that connects that is on a Bean on a jsp file.
The method will make a request to a RMI Server and return a string.
At this point the method is just return a pre-defined string for test.

This is the bean method:

public String getListProjects() throws RemoteException {

    this.dataToSend = new Object[2];
    this.dataToSend[1] = 0;

    this.postCard = new ClientRequest("2", this.dataToSend, "tempo");

    try{
      this.postCard = this.connectToRMI.getActualProjects(this.postCard);
    }catch(Exception e){
      e.printStackTrace();
    }

    return "Hello";

}

And this is the jsp code:

<h1>Projectos Actuais</h1>

<h2><%

    fundstarter.model.ConnectToRMIBean aux = new       fundstarter.model.ConnectToRMIBean();
    try{
        aux.getListProjects();
    }catch(Exception e){
        e.printStackTrace();
    }

    %>
</h2>

I'm guiding my self from another code, and the method is called like this. But in my case it's not working, and I can't figure out what is wrong.


Solution

  • Quoting and fixing your latest change on edit with some comments:

    <h1>Projectos Actuais</h1>
    
    <h2><%
        try{        
          fundstarter.model.ConnectToRMIBean aux = new       fundstarter.model.ConnectToRMIBean();
    
          //Send result into generated HTML page with out.print!
          out.print(aux.getListProjects());
        }catch(Exception e){
            e.printStackTrace();
        }
    
        %>
    </h2>