How to obtain request / session / servletcontext attribute in JSP using EL?

前端 未结 1 1427
野趣味
野趣味 2020-12-02 23:09

I know this isn\'t hard, but I\'m not having any luck.

I want to make fooList from a Servlet available in a JSP. So in the Servlet I have:



        
相关标签:
1条回答
  • 2020-12-02 23:48

    It's just the attribute name as you've set yourself here:

    request.setAttribute("list", fooList);
    

    It's thus "list":

    ${list}
    

    This works the same way for session.setAttribute("name", value) and application.setAttribute("name", value). The value is in EL available by just ${name}.


    More detail: EL uses by default PageContext#findAttribute() which scans in subsequently the page, request, session and application scopes for the firstnext non-null attribute value matching the given attribute name.

    If you'd like to explicitly specify the scope for the case that you've multiple attributes with the same name in different scopes, then normal approach is to use ${pageScope}, ${requestScope}, ${sessionScope} or ${applicationScope}. E.g.

    ${requestScope.list}
    

    See also:

    • Unified expression language in Java EE 5 tutorial
    0 讨论(0)
提交回复
热议问题