How to call a Java method with arguments which is defined in Java class, from JSP using JSTL/EL. The method is returning arrays. Any return value can be used.
相关问题
- JSF2 composite cc.attrs expression does not evalua
- #{facesContext} EL expression not resolved at runt
- jsp caching tag library
- JSP template implementation (Composite View Patter
- how to add a list of string into json object in js
相关文章
- jsp里面的画布功能,为什么会出错?求大佬找下问题
- JSP String formatting Truncate
- Forward request from servlet to jsp
- Comparing string and boolean in Expression languag
- If CancellationToken is a struct and is passed by
- Accessing variables in a function within a functio
- JSTL Date comparison
- Passing a Java object value in Custom JSP tag
Give the JSP a reference to an instance of the class that has the method and call it.
You're probably asking who gives the JSP that instance - it's a servlet in the model-2 MVC arrangement.
Here's how the flow will work:
You can only invoke methods with arguments in EL if you're targeting and running a Servlet 3.0 compatible container (e.g. Tomcat 7, Glassfish 3, JBoss AS 6, etc) with a
web.xml
declared conform Servlet 3.0. This servlet version comes along with EL 2.2 which allows invoking arbitrary instance methods with arguments.Assuming that you've a
${bean}
in the scope which refers to an instance of a class which has a method something likepublic Object[] getArray(String key)
, then you should be able to do this:or even with another variable as argument
But if you don't target a Servlet 3.0 container, then you cannot invoke methods with arguments in EL at all. Your best bet is to just do the job in the preprocessing servlet as suggested by Duffymo.
As a completely different alternative, you could create an EL function which delegates the method call. You can find a kickoff example somewhere near the bottom of this blog. You'd like to end up something like as:
with
The above solution didnt work for me. I had a function
getRemitanceProfileInformation(user)
in my java class. I created a usebean of java class and then invokedand it worked.
If you're using JSF, you can use an bean act as a model in View Scope, and load from data source automatic. And if you're using JSP, how about using TLD Tag? And using JSTL tag
<c:foreach>
? It's saves the memory from saving in the session, or save in session and remove it when load event done? Some how like this (JSTL+TLD)