session.setAttribute()方法是做什么用的?

xyyyy 2003-07-15 03:45:39
session.setAttribute()方法是做什么用的?
哪位能给个详细的说明
...全文
54745 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
amortal 2003-07-15
  • 打赏
  • 举报
回复
session.setAttribute("xyyyy",xyyy);保存
session.getAttribute("xyyyy");取得
你可以把自己要的数据什么的放在session里面传来传去的,很好玩的~
pleonheart 2003-07-15
  • 打赏
  • 举报
回复
我靠,楼上两个也太快了吧
pleonheart 2003-07-15
  • 打赏
  • 举报
回复
import javax.servlet.http.*;

pulic class setSession {

public setSession (HttpServletRequest httpServletRequest) {
String xyyyy = "xyyyy";
HttpSession session = httpServletRequest.getSession();
session.setAttribute("xyyyy",xyyy);
}

}
mingjob 2003-07-15
  • 打赏
  • 举报
回复
往session中设置一个变量的值,你以后可用getAttribute()来获取和使用它。详细说明如下:

setAttribute
public void setAttribute(java.lang.String name,
java.lang.Object value)
Binds an object to this session, using the name specified. If an object of the same name is already bound to the session, the object is replaced.
After this method executes, and if the new object implements HttpSessionBindingListener, the container calls HttpSessionBindingListener.valueBound. The container then notifies any HttpSessionAttributeListeners in the web application.

If an object was already bound to this session of this name that implements HttpSessionBindingListener, its HttpSessionBindingListener.valueUnbound method is called.

If the value passed in is null, this has the same effect as calling removeAttribute().

Parameters:
name - the name to which the object is bound; cannot be null
value - the object to be bound
Throws:
java.lang.IllegalStateException - if this method is called on an invalidated session
flowercat 2003-07-15
  • 打赏
  • 举报
回复 1
session.setAttribute("sessionName",Object);
用来设置session值的,sessionName是名称,object是你要保存的对象。
session.getAttribute("sessionName");
用来得到对应名称的session值,即得到object对象,注意需要进行类型转换!

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧