• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

JSTL statc java method call

 
Ranch Hand
Posts: 198
Oracle Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Bartender
Posts: 4101
63
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know how to use EL functions? You may check our FAQ entry DefineELFunctions.
 
Prabhakar Reddy Bokka
Ranch Hand
Posts: 198
Oracle Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But how can i insert this in my jsp??

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry page got resubmitted!!
 
Prabhakar Reddy Bokka
Ranch Hand
Posts: 198
Oracle Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 4101
63
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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...
 
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Marshal
Posts: 67275
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!