Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSTL statc java method call

 
Prabhakar Reddy Bokka
Ranch Hand
Posts: 197
Java Oracle Spring
  • 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

 
Vijitha Kumara
Bartender
Pie
Posts: 3918
10
Chrome Fedora Hibernate
  • 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: 197
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But how can i insert this in my jsp??

 
dileep keely
Ranch Hand
Posts: 108
  • 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: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry page got resubmitted!!
 
Prabhakar Reddy Bokka
Ranch Hand
Posts: 197
Java Oracle Spring
  • 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: 108
  • 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
Pie
Posts: 3918
10
Chrome Fedora Hibernate
  • 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...
 
Hebert Coelho
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic