• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to use Java Application in jsp:useBean

 
Raghuraman Muthuswamy
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • 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
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!