jsp中PageContext域对象的getAttribute和findAttribute方法的区别

两者的API如下:

abstract public Object getAttribute(String name)
返回与页面范围中的名称关联的对象,如果该对象不存在,则返回 null。 name 要获取的属性的名称 
return 与页面范围中的名称关联的对象,如果该对象不存在,则返回 null。 
Throws NullPointerException: 如果名称为 null。 


英文文档: 
getAttribute

public abstract Object getAttribute(String name)Returns the object associated with 
the name in the page scope or null if not found. 

Parameters:
name - the name of the attribute to get 
Returns:
the object associated with the name in the page scope or null if not found. 
Throws: 
NullPointerException - if the name is null
abstract public Object findAttribute(String name)
按顺序在页面、请求、会话(如果有效)和应用程序范围中搜索指定属性,并返回关联的值或 null。 
name 要搜索的属性的名称 
return 关联的值或 null 
Throws NullPointerException: 如果名称为 null。 


英文文档: 
findAttribute

public abstract Object findAttribute(String name)Searches for the named attribute in
page, request, session (if valid), and application scope(s) in order and returns the 
value associated or null. 

Parameters:
name - the name of the attribute to search for 
Returns:
the value associated or null 
Throws: 
NullPointerException - if the name is null

参考 findAttribute()与getAttribute()的区别

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容