yatinbc
yatinbc

Reputation: 625

How to call method from jar file in JSP?

I have Java program in that I have database connectivity, and few methods to be call to run SQL query. I generated jar file for that java file using Apache ANT. now I imported that jar file in my JSP. now how to call method executeQuery(String sql) from that jar file which is present in that Java file.

Upvotes: 2

Views: 9769

Answers (4)

Jayant Varshney
Jayant Varshney

Reputation: 1825

firstly place your external .jar to the lib folder of your application (WEB-INF/lib) then simply you have to import that class or package of the jar file which you want to use by using import tag of the jsp.

<%@ page import="yourPackage.ClassName" %>

and now you can simply call your method on the object of that class as you do in simple java program

Upvotes: 0

KV Prajapati
KV Prajapati

Reputation: 94645

In order to use external .jars in your webapp, these JARs must be placed under WEB-INF/lib folder and you want to call a method - executeQuery(String sql) defined in XXXXX class.

If that type XXXX is public and

  1. Method executeQuery(String sql) is public static then call this method via
    XXXX.executeQuery(param) syntax;
  2. If it is an public instance method then create an object of XXXX type and call it.

Upvotes: 2

Dangling Piyush
Dangling Piyush

Reputation: 3676

Why import a separate jar file to perform this you should use

SQL TAG LIBRARY

Upvotes: 1

user804690
user804690

Reputation:

You shouldn't do that in a JSP (presentation layer), but if you really want that you have to import the class/classes with the following line in JSP:

<%@ page import="package1.myClass1,package2.myClass2,....,packageN.myClassN" %>

Upvotes: 0

Related Questions