这是相同或不同的pageContext Scope和JSP页面中的一些Implicit对象吗? [英] Is this are same or different pageContext Scope and some of Implicit objects things in JSP Page?

查看:83
本文介绍了这是相同或不同的pageContext Scope和JSP页面中的一些Implicit对象吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个东西是相同的还是不同的,如果不同那么请给我理由和如何?

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

1)pageContext.setAttribute(first,value1,pageContext.REQUEST_SCOPE);

1) pageContext.setAttribute("first","value1",pageContext.REQUEST_SCOPE);

2)
pageContext.setAttribute(first, value1,pageContext.SESSION_SCOPE);

2) pageContext.setAttribute("first","value1",pageContext.SESSION_SCOPE);

3)
pageContext.setAttribute(first,value1,pageContext.APPLICATION_SCOPE);

3) pageContext.setAttribute("first","value1",pageContext.APPLICATION_SCOPE);

application.setAttribute(first,value1);

application.setAttribute("first","value1");

推荐答案

在JSP页面中,您最多可以放置4个位置,您可以在其中放置对象以便以后检索它们。

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

1)页面范围

无论您在页面范围内放置什么内容,都只能在那里使用。包含via或转发的同一请求中的任何其他页面都不会看到该对象,因为它们定义了自己的页面范围,该范围不包含调用页面的页面范围。

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.

这是默认范围,因此调用 pageContext.setAttribute(a,b,PageContext.PAGE_SCOPE); 与调用 pageContext相同.setAttribute(a,b);

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

2)请求范围

您在请求范围内提供的内容可用于为此JSP页面提供服务的所有页面。因此,包含或转发的其他页面(不是HTTP重定向)将共享此上下文,并可以访问在调用页面上下文中声明的属性。

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.

调用 pageContext .setAttribute(a,b,PageContext.REQUEST_SCOPE); 与调用 request.setAttribute(a,b);

3)会话范围

您在会话范围内的内容可用于所有请求在同一个用户会话上。

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

调用 pageContext.setAttribute(a,b,PageContext.SESSION_SCOPE); 与调用 session.setAttribute(a,b)相同;

4)应用程序范围

您在应用程序范围内放置的内容可用于应用程序的所有请求(即由所有用户共享)。这意味着生命周期基本上与应用程序运行一样长。所以你通常不想使用这个。

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.

调用 pageContext.setAttribute(a,b,PageContext.APPLICATION_SCOPE) ; 等于调用 application.setAttribute(a,b);

这篇关于这是相同或不同的pageContext Scope和JSP页面中的一些Implicit对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆