• 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

How to use Java Application in jsp:useBean

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,
I have a java class DB.java which has JDBC code in it. A JSP page is accessing the java file. I used the import statement in <%@ page %> to access the Java file. Now i know we can use the useBean concept to access standalone Java file. But when using useBean how to access the methods in the Java File.

<jsp:useBean id="name" class="project.DB"/>

I want to access a method processDB in the Java File. How to access the method.

In normal import="project.*" i will create object for the class DB db = new DB() and call db.processDB(); from the original Java file.

How to call this method using useBean concept. Your suggestion is very much appreciated.

Thanks in advance,

Regards,
Raghu
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. You can just use setProperty and getProperty methods.
 
Raghuraman Muthuswamy
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Adeel,
I have used a Java application program in the JSP page using jsp:useBean. The syntax i used is,

<jsp:useBean id="name" class="project.DB"/>

The file DB.java has a method processDB. This method returns a HashMap. To access that method in JSP, I used,

<%
HashMap h = new HashMap();
h = name.processDB();
%>

The name is the id of the bean. I got this idea from a website.

Thanks for your reply,

will post more queries,

regards,
Raghu
 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do it this way..



You are, otherwise, unnecessarily creating an extra HashMap object.

By the way, what Adeel meant when he said 'No' to your first post was that the syntax of the useBean tag does not give you an easy way to invoke methods (other than the get and set methods) on the bean.
You would have to do it the scriptlet way as you have posted subsequently.

ram.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ramprasad madathil:
By the way, what Adeel meant when he said 'No' to your first post was that the syntax of the useBean tag does not give you an easy way to invoke methods (other than the get and set methods) on the bean.
You would have to do it the scriptlet way as you have posted subsequently.



Very nicely picked, I must say.
 
Screaming fools! It's nothing more than a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic