Hi there ,

We know that we can use taglibs in JSP page. Is it possible to refer tlds and its tags from the servlets. Can we have control over the taglibs in the servlet programmatically ? I googled but invain. All the results are about creating custom taglibs.

Any help would be appreciated. Thanks in advance.

Answer is NO! Tag lib is just to use functions of java in jsp page, why to use library in servlet when you have java core functions already there.
Can you give me example when would you use that in servlets?

what you said is correct milil. but I'm not sure about it.

I am using a reporting tool . its vendor provided a taglib. I use it by a taglib directive in jsp page.

after getting some data from a form(using ajax), we pass those values to that reporting tool via its taglib(we get those parameter values in a ajax response (jsp) page where tags are used).

as a result it returns data and shows it on the UI(using ajax).

this is what usual thing that happens.

Now there is a new requirement. according to it, we should make this report accessible to single user at a time.

i planned to use a servlet for this. also i need to use a synchronized block in that servlet.

in the synchronized block, i'm going to use those taglibs because those tags are going to generate that report after getting some parameters from the UI form.

so to make use of those tags, i got this idea(using taglib in a servlet).

Is there any other way to do it ?

Thanks :)

What I do to create reports from database is iReport.
You can draw what kind of report you want, then convert that to jasper report.
When you have it done it is just sending list of values to that report and he will know how to hande it.
So you will have something like this.
Press button to generate report let say monthly sales.
Your servlet is called, he goes in database grab all values that he need.
Send that values to this compiled jasper report.
And you specify how would that report look like. I always put PDF.
Then after clicking on button user will get pdf opened with values you need.
I don't know what kind of report you need I never work with that kind of taglbis, if you want I can show you my code how it generates PDF with jasper reports.

Now only i heard about iReport.
Thats sounds great. But I couldn't implement that iReport in the ongoing project because its almost done. I will give a try to it later. I would be greatful to you if you could tell me more about iReport.

Let me come to this topic. There is NO solution to this issue. So,I changed my approach. Thanks to The AJAX. Eventhough we have AJAXified many things in the project, it didn't come to my mind. As I changed the logic slightly, again I'm on the right track.

So, that approach is :

Before generating that report, we need to do some analytics. An analytical tool(R) will execute a set of modules that creat a temporary table in the database from which that reporting tool will fetch the information.

java code needed to call that analytics modules(is synchronized) will be given in that servlet(which I planned to create). The existing taglibs are not modified and are allowed to stay in their JSP page.

After getting the form information from the UI, I wont send those data to the jsp where taglibs live. Instead , I send only two params(of entire form data) to the servlet via ajax.

When the servlet finishes its job, it returns a status to UI.

After knowing the servlet has done, again the UI send those temporarily stored form data in a new request to the jsp page of that taglibs. now its done.

Thanks for your time and ideas milil. Thank you so much.

Now only i heard about iReport. Thats sounds great. But I couldn't implement that iReport in the ongoing project because its almost done.

How do you figure that? If having a report is part of the project, it won't be 'done' unless the report is implemented.

I mean we are using another/different reporting tool . We created many reports based on it. So, no need of another reporting tool.

I had an issue in the existing report when I was trying to implement another/new requirement.