• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help with calling EJB in jsp page

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys,

I am trying to learn JSP through books and online tutorials. I downloaded the Duke Bookstore app. Got this app running and have made some mods to the entry .jsp page. I am having trouble understanding what is going on with the Bean used in the following page. The bean is using a valiue of an object "value="<%=bookDBEJB%". I look at the code for bookDBEJB and I dont see where information is being used. At this point I am scratching my head!!!I hope that I have provided enough information for someone to point me in the right direction. Thanks in advance.
-------------------------------------------------------------------------
I received a reply to the post in the ejb section.
THis is a JSP question, you would get better responses if posted in the JSP forum..
code:


<jsp:setProperty name="bookDB" property="database" value="<%=bookDBEJB%>" />


The above line is equivalent to calling bookDB.setDatabase(...), where the argument to the method is an object of type BookDBEJB, in your case whatever is represented by bookDBEJB.

Hope this helps.
---------------------------------------------------------------
Where does the object bookDBEJB get created?

Here is the code for the page that uses the bean:

<jsp:useBean id="bookDB" class="database.BookDB" scope="page" >
<jsp:setProperty name="bookDB" property="database" value="<%=bookDBEJB%>" />

</jsp:useBean>

<p><b>Lets see what happens here:</b></p>
<p><b><%=messages.getString("What")%></b></p>
<%

bookDB.setBookId("209");
BookDetails bd = bookDB.getBookDetails();

%>
------------------------------------------------------------------
package database;
import javax.ejb.*;
import javax.naming.*;
import java.sql.*;
import java.util.*;
import exception.*;

public class BookDB {

private String bookId = "0";
private BookDBEJB database = null;

public BookDB () {
}

public void setBookId(String bookId) {
this.bookId = bookId;
}

public void setDatabase(BookDBEJB database) {
this.database = database;
}

public BookDetails getBookDetails() throws Exception {
try {
return (BookDetails)database.getBookDetails(bookId);
} catch (BookNotFoundException ex) {
throw ex;
}
}

public Collection getBooks() throws Exception {
try {
return database.getBooks();
} catch (BooksNotFoundException ex) {
throw ex;
}

}

public int getNumberOfBooks() throws Exception {
try {
return database.getNumberOfBooks();
} catch (BooksNotFoundException ex) {
throw ex;
}
}
}
----------------------------------------------------------
package database;

import java.util.*;
import javax.ejb.*;
import java.rmi.RemoteException;
import exception.*;

public interface BookDBEJB extends EJBObject {
public BookDetails getBookDetails(String bookId) throws RemoteException, BookNotFoundException;
public int getNumberOfBooks() throws RemoteException, BooksNotFoundException;
public Collection getBooks() throws RemoteException, BooksNotFoundException;
}
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved to the EJB forum.
 
tim mahoney
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is funny. First post in JSP. Told to move to EJB forum. Then told to move to the JSP Forum. Now back in the EJB forum. Is this a government run forum?
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tim,


Is this a government run forum?


This is a good one.


The bean is using a valiue of an object "value="<%=bookDBEJB%". I look at the code for bookDBEJB and I dont see where information is being used. At this point I am scratching my head!!!I hope that I have provided enough information for someone to point me in the right direction. Thanks in advance.


<%=bookDBEJB%> is an expression element that is evaluated, converted to a String, and inserted into the response where the expression appears in the JSP page. Somewhere the bookDBEJB variable is defined and not necessary inside the same jsp, probably using a declaration. Something like this:

It could be defined inside another jsp that includes this one. Another technique is to use a custom tag that defines scripting variables. What I would advice you to do is to perform a search for all files that contains the bookDBEJB symbol and find out where this variable is defined.
Regards.
reply
    Bookmark Topic Watch Topic
  • New Topic