Are session and sessionScope the same in JSP EL?

后端 未结 5 2061
[愿得一人]
[愿得一人] 2020-12-02 20:58
public class LoginAction extends ActionSupport {
    private String username;
    private String password;

    @Override
    public String execute() throws Exceptio         


        
5条回答
  •  误落风尘
    2020-12-02 21:39

    By default page, request, session and application scope objects are available to JSP pages. So you can access then using EL syntax.

    And following table shows IMPLICIT objects available to EL.

           Implicit object            Description
    1.     pageScope        Scoped variables from page scope
    2.     requestScope     Scoped variables from request scope
    3.     sessionScope     Scoped variables from session scope
    4.     applicationScope Scoped variables from application scope
    5.     param            Request parameters as strings
    6.     paramValues      Request parameters as collections of strings
    7.     header           HTTP request headers as strings
    8.     headerValues     HTTP request headers as collections of strings
    9.     initParam        Context-initialization parameters
    10.    cookie           Cookie values
    11.    pageContext      The JSP PageContext object for the current page
    

    So session and sessionScope are same but differs in context they are used.More specifically session is object and sessionScope is map (key, value) of Attribute and its value.

    • If you say ${session.sessionAttr} it refers to session object available to JSP page.
    • If you say ${sessionScope.sessionAttr} it refers to IMPLICIT session object available to EL.
    • Or if you just say ${attrName} it will search attrName in all scope from page to application scope.

提交回复
热议问题