It's not a secret anymore!
The moose likes JSP and the fly likes JSP question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP question" Watch "JSP question" New topic

JSP question

Subha Rangu

Joined: Jul 23, 2004
Posts: 29
How do I include a Java class in a JSP page.
Say I have a searchresults.jsp page in which Search.class has a set of results. I just want to see Search.class in searchResults.jsp instead of doing java Search @ command prompt.
SrinivasanRG Gopal

Joined: Aug 05, 2004
Posts: 5
Use the useBean tag in your JSP (For oading Java classes).
First, write a method in your Java program ( to return the results (can be any array / object / any valid Java data type) instead of doing it in the main().

Next, in the JSP program, give the useBean tag as such.
The useBean tag is like this.

<jsp:useBean id="fff" name="yourJavaBeanNameWithFullPackageStructure" scope="page"/>

The id is the identifier by which you can access the bean in the JSP page.

Suppose the method is getResults() and returns a String Array,
in your JSP, you will code as :

String[] results = fff.getResults();

Hope it helps

I agree. Here's the link:
subject: JSP question
jQuery in Action, 3rd edition