简体   繁体   中英

Call method from jsp using jstl

I have a condition where i want to pass EL, element.dept_id as parameter and get the name of department from a method as return. I want it directly from view page if possible. However, the return will be object of type department and i want to print the name of department. Any help? Can it be done without using scriptlet?

class Department{
Private Integer id;
Private String name;
//getters
//setters
}

 <c:forEach items="${empImpl.allEmployee}" var="element">

      <tr>
    <td><c:out value="${element.name}" /></td>
    <td><c:out value="${element.gender}" /></td>

    <td><c:out value="${element.salary}" /></td>

    <td>Something like this // deptImpl.name(${element.dept_id})  </td>

You could do it by defining a custom EL function taking an id and returning your department. Check out Custom Tags and Custom EL Functions in JSP Pages for an example of how to create a custome EL function.

However, I'd recomend just having your servlet populate the request with the data you want to display since that would make your code easier to maintain.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM