当前位置: 动力学知识库 > 问答 > 编程问答 >

java - How to store session while sendRedirect

问题描述:

I have a condition where I want to remove the attribute from the session and I am doing response.sendRedirect after that.

But I am not sure if it will remove the session attribute ? Any thoughts ?

P.S. I have to do sendRedirect, I cannot use forward.

session.removeAttribute(Constants.USER_REQUEST_URI);

response.sendRedirect(userReqUri);

ANSWER : Just a little debugging solved my concern. I checked the session attribute value by getting the variable and it was null. So it removed the variable from the session.

网友答案:

Yes, if Constants.USER_REQUEST_URI gives the correct name as it is stored in session, then it will remove them.

Session work differently than GET and POST request so redirecting and forwarding will make no difference.

Good way to confirm this, would be to check if the variable is accessible after the redirect

session.getAttribute(Constants.USER_REQUEST_URI)
分享给朋友:
您可能感兴趣的文章:
随机阅读: