This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JSP and the fly likes JSTL statc java method call Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "JSTL statc java method call" Watch "JSTL statc java method call" New topic
Author

JSTL statc java method call

Prabhakar Reddy Bokka
Ranch Hand

Joined: Jul 26, 2005
Posts: 193

Hi,

I need to call a static utility method from JSP, and I am using JSTL.
Can any one advice how to call static methods of a class from JSP??



I want to call this in my JSP like below



SCJP 5, SCWCD 5
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3833

Do you know how to use EL functions? You may check our FAQ entry DefineELFunctions.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Prabhakar Reddy Bokka
Ranch Hand

Joined: Jul 26, 2005
Posts: 193

But how can i insert this in my jsp??

dileep keely
Ranch Hand

Joined: Jun 28, 2010
Posts: 91


The link says to add in the Tag library descriptor and reference in jsp.

"In order to define an EL function, a <function> element must be added to an existing or new TLD file that is in the scope of your application and declared within the referencing JSP page. For our example, if we wanted to name the EL function the same name as the static method (though they do not need to be the same), we could add"

Please go through the information provided in the link again.
dileep keely
Ranch Hand

Joined: Jun 28, 2010
Posts: 91
Sorry page got resubmitted!!
Prabhakar Reddy Bokka
Ranch Hand

Joined: Jul 26, 2005
Posts: 193

I do not have any tlds in my project.

Do i need to create a new tld specially for this? This seems bit lenthy process.

Don't we have any other way to call the a method directly in JSP using JSTL?
dileep keely
Ranch Hand

Joined: Jun 28, 2010
Posts: 91
Do i need to create a new tld specially for this? This seems bit lenthy process.
yes
Don't we have any other way to call the a method directly in JSP using JSTL?
Using the EL function was the better way, but lets see if we can get some hints/ inputs.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3833

Prabhakar Reddy Bokka wrote:... Don't we have any other way to call the a method directly in JSP using JSTL?

Doing so (using scriptlet) is very old fashioned and considered a very bad practice...
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

Vijitha Kumara wrote:
Prabhakar Reddy Bokka wrote:... Don't we have any other way to call the a method directly in JSP using JSTL?

Doing so (using scriptlet) is very old fashioned and considered a very bad practice...


Scriplet may help you. But as Vijitha said: "is very old fashioned and considered a very bad practice".

Create your tld and use it.


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61314
    
  66

Once you've created a TLD, it can be used not only to hold EL functions, but custom tags, and tag file declarations. It's a very useful element to have in your project to define project-specific JSP elements.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
GeeCON Prague 2014
 
subject: JSTL statc java method call