当前位置: 技术问答>java相关
关于SESSION和SESSION BEAN
来源: 互联网 发布时间:2015-04-03
本文导语: 目前做一个系统,用JSP构建客户端,用SERVLET封装业务逻辑。分别在UNIX和NT上测试,用的都是WEBSPHERE做应用服务器。考虑的校验用户权限,在用户登陆后,将用户的信息写在一个BEAN中,并申明为这种形式,在这里面有...
目前做一个系统,用JSP构建客户端,用SERVLET封装业务逻辑。分别在UNIX和NT上测试,用的都是WEBSPHERE做应用服务器。考虑的校验用户权限,在用户登陆后,将用户的信息写在一个BEAN中,并申明为这种形式,在这里面有两个方法,分别取用户名和用户职务。我用这样一段程序校验SESSION是否失效奇怪的事情发生了,我在对zwdm进行比较的时候,用zwdm.compareTo("110")==0的时候,保空异常。因为zwdm=null,这是为什么呢?session 失效了吗?
望指点,多谢!
望指点,多谢!
|
你用response.sendRedirect的时候,session失效
应该在response.sendRedirect之前用java.lang.String response.encodeRedirectURL(/tech-qa-java/java.lang.String url)方法encode url
具体用法
encodeRedirectURL
public java.lang.String encodeRedirectURL(/tech-qa-java/java.lang.String url)Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged. The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. Because the rules for making this determination can differ from those used to decide whether to encode a normal link, this method is seperate from the encodeURL method.
All URLs sent to the HttpServletResponse.sendRedirect method should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.
Parameters:
url - the url to be encoded.
Returns:
the encoded URL if encoding is needed; the unchanged URL otherwise.
应该在response.sendRedirect之前用java.lang.String response.encodeRedirectURL(/tech-qa-java/java.lang.String url)方法encode url
具体用法
encodeRedirectURL
public java.lang.String encodeRedirectURL(/tech-qa-java/java.lang.String url)Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged. The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. Because the rules for making this determination can differ from those used to decide whether to encode a normal link, this method is seperate from the encodeURL method.
All URLs sent to the HttpServletResponse.sendRedirect method should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.
Parameters:
url - the url to be encoded.
Returns:
the encoded URL if encoding is needed; the unchanged URL otherwise.
|
NT只将jsp页定义成有问题的,我也遇到过
解决办法是,将验证,写信息,读信息也时bean的*.java中即在你的com.SessionBean中首次登陆时做验证,成功后将信息写入session如
HttpSession session;//成员变量
String zgmc="";
public void SetSession()
{
session.setMaxInactiveInterval(1000);//设置session时间属性
session.setAttribute("zgmc", zgmc );
......
}
jsp取session的函数为
void SetSession()
{
session.setAttribute("zgmc", zgmc );
......
}
public String getZgmc()
{
zgmc=session.getAttribute("zgmc").toString();//异常什么的要处理,我只简单提一下
return zgmc;
}
解决办法是,将验证,写信息,读信息也时bean的*.java中即在你的com.SessionBean中首次登陆时做验证,成功后将信息写入session如
HttpSession session;//成员变量
String zgmc="";
public void SetSession()
{
session.setMaxInactiveInterval(1000);//设置session时间属性
session.setAttribute("zgmc", zgmc );
......
}
jsp取session的函数为
void SetSession()
{
session.setAttribute("zgmc", zgmc );
......
}
public String getZgmc()
{
zgmc=session.getAttribute("zgmc").toString();//异常什么的要处理,我只简单提一下
return zgmc;
}
|
用session.setAttribute("name",Object)会好吧
他好象试销的机会少点
我的感觉
他好象试销的机会少点
我的感觉