Is this are same or different pageContext Scope and some of Implicit objects things in JSP Page?

前端 未结 2 1230
耶瑟儿~
耶瑟儿~ 2021-02-03 11:33

This things are same or different if different then please give me reason for that and How?

this things are in scriplet..

1) pageContext.setAttribute(\"first\"

相关标签:
2条回答
  • 2021-02-03 12:15

    In JSP pages you have up to "4 places" where you can put objects to retrieve them later.

    1) Page scope

    Whatever you put into your page scope is available only there. Any other page in the same request included via or forwarded will not see the object since they define their own page scope which does not contain the page scope of the calling page.

    This is the default scope, so calling pageContext.setAttribute("a", "b", PageContext.PAGE_SCOPE); is the same as calling pageContext.setAttribute("a", "b");

    2) Request scope

    What you put on your request scope is available across all the pages of the request serving this JSP page. So other pages included or forwarded (not HTTP redirect) will share this context and can access the attributes declared in the calling page context.

    Calling pageContext.setAttribute("a", "b", PageContext.REQUEST_SCOPE); is the same as calling request.setAttribute("a", "b");

    3) Session scope

    What you put on your session scope is available across all requests on the same user session.

    Calling pageContext.setAttribute("a", "b", PageContext.SESSION_SCOPE); is the same as calling session.setAttribute("a", "b");

    4) Application scope

    What you put on your application scope is available across all requests on your application (i.e. is shared by all users). This implies a lifetime that is basically as long as the application is running. So you generally don't want to use this one.

    Calling pageContext.setAttribute("a", "b", PageContext.APPLICATION_SCOPE); is equal to calling application.setAttribute("a", "b");

    0 讨论(0)
  • 2021-02-03 12:17

    all three are basically same just different way of setting variable in respective scopes.
    check this article. It states that third parameter for setAttribute method defines the scope in which variable need to set.

    So in your case first will set value in request scope, second will set it in session and third will set it in application scope.

    0 讨论(0)
提交回复
热议问题