• 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

JSP question

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use the useBean tag in your JSP (For oading Java classes).
First, write a method in your Java program (Search.java?) 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic