请问:
A a=new A();
HttpServlet.session.setAttribute("a",a);
和
HttpServlet.session.setAttribute("a",new A());
有什么区别?
我在getAttribute("a")的时候。。第一个能得到放入对象a中的值,而第二个总是空指针!
A a=new A();
HttpServlet.session.setAttribute("a",a);
和
HttpServlet.session.setAttribute("a",new A());
有什么区别?
我在getAttribute("a")的时候。。第一个能得到放入对象a中的值,而第二个总是空指针!
解决方案 »
- 请教 java基本数据类型动态转换
- 我想建设一个自己的网站,谁来给支支招?
- Servlet如何处理另一个系统发过来的请求。
- struts2 spring hibernate 页面跳转后 form表单数据清除问题
- weblogic9.1 上部署web,jsp 中<%@ inculde file=""%>问题
- 关于在dreamweaver(HTML)中编写javascript的问题
- jboss 无法用本机ip地址访问,只能用localhost或127.0.0.1访问
- 学习jsp,oracle,环境apache+resin。请介绍一些相关的学习资料,感激!!
- 请教各位,用J2EE架构,WEB应用服务器哪个比较好?
- 面试题,关于线程同步的
- 数据库插入操作
- list 遍历问题
<%
request.getSession(true).setAttribute("a",new test.GetData());
test.GetData gd=(test.GetData)request.getSession().getAttribute("a");
if(gd==null){
out.println("is null");
}else{
out.print("not null");
}
%>
这个“a”可以看作是我们存放在session里的对象的名字。
跟存自行车一个道理,你存的时候人家给你个号码是222,等你要去取自行车的时候,你给人家个333的号码,能取到你的车子吗?取到的会是车子吗?
谢谢大家的关心。。是我表述有误。。回去加强学习。。
A a=(A)session.getAttribute("a");
if(a==null)
{a=new A();
HttpServlet.session.setAttribute("a",a);
//
HttpServlet.session.setAttribute("a",new A());}