简体   繁体   English

servlet中的findAttribute()和getAttribute()方法有什么区别?

[英]What's the difference between the methods findAttribute() and getAttribute() in servlet?

If I've set "cart" as a session attribute, then what's the difference between the methods pageContext.findAttribute("cart") and session.getAttribute("cart") in servlet file ? 如果将“ cart”设置为会话属性,那么servlet文件中的pageContext.findAttribute("cart")session.getAttribute("cart")方法有什么区别? Do they do the same thing in this case? 他们在这种情况下是否做同样的事情?

Was it really too much effort to read the Javadoc for PageContext.findAttribute() ? 阅读PageContext.findAttribute()的Javadoc真的花费了太多精力吗?

The PageContext looks in multiple scopes for the attribute (page, request, session then application) whereas the session.getAttribute() only looks in the session. PageContext在多个作用域中查找属性(页面,请求,会话然后是应用程序),而session.getAttribute()仅在会话中查找。 If you know the attribute is in the session, then session.getAttribute() should be (marginally) faster. 如果您知道该属性在会话中,则session.getAttribute()应该(略微)更快。

Object findAttribute (String AttributeName) : This method searches for the specified attribute in all four levels in the following order – Page, Request, Session and Application. 对象findAttribute(字符串AttributeName) :此方法按以下四个顺序在所有四个级别中搜索指定的属性-页面,请求,会话和应用程序。 It returns NULL when no attribute found at any of the level. 如果在任何级别都没有找到属性,则返回NULL。

session.getAttribute("cart"): This method searches for the specified attribute in only Session scope. session.getAttribute(“ cart”):此方法仅在Session范围内搜索指定的属性。

Do they do the same thing in this case? 他们在这种情况下是否做同样的事情? => They do same thing in this case if you dont have attribute name cart in Page, Request. =>如果您在“页面,请求”中没有属性名称购物车,则在这种情况下它们也会执行相同的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Selenium WebDriver 中的 getText() 和 getAttribute() 有什么区别? - What is the difference between getText() and getAttribute() in Selenium WebDriver? Servlet 响应方法 addHeader 和 setHeader 之间有什么区别? - What is the difference between Servlet response methods addHeader and setHeader? Java中的块和方法有什么区别? - What's the difference between blocks and methods in Java? “configure”和“configureGlobal”方法有什么区别? - What's the difference between 'configure' and 'configureGlobal' methods? 这两种通用方法有什么区别? - What's difference between these two generic methods? getAttribute()和getParameter()之间的区别 - Difference between getAttribute() and getParameter() portlet 和 servlet 有什么区别? - what is the difference between a portlet and a servlet? Calendar 的 getActualMinimum 和 getGreatestMinimum 方法有什么区别? - What's the difference between Calendar's getActualMinimum and getGreatestMinimum methods? EasyMock 的.andReturn 和.andAnswer 方法有什么区别? - What's the difference between EasyMock's .andReturn and .andAnswer methods? HttpServletRequest中getRequestURI和getPathInfo方法之间的区别是什么? - What's the difference between getRequestURI and getPathInfo methods in HttpServletRequest?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM