如何检查 Struts 2 jsp 中的有效会话?
我的所有页面上都有一个包含jsp,其中包含js文件,css文件等。这个包含jsp也指的是带有“”的会话。
在我的应用程序的最后一页上,该操作对 HttpSession 对象执行 session.invalidate。
因此,当我的应用程序的最后一页出现并运行“”时,由于会话无效,我收到以下错误
2011-10-19 10:30:59,134 警告 com.opensymphony.xwork2.ognl.OgnlValueStack - 针对值堆栈计算表达式“#session.user.isWhatever()”时捕获异常 java.lang.IllegalStateException:getAttribute:会话已失效 在 org.apache.catalina.session.StandardSession.getAttribute(StandardSession.java:1062) 在 org.apache.catalina.session.StandardSessionFacade.getAttribute(StandardSessionFacade.java:110) 在 org.apache.struts2.dispatcher.SessionMap.get(SessionMap.java:165) 在 ognl.MapPropertyAccessor.getProperty(MapPropertyAccessor.java:76)
我尝试过“#session neq null”来阻止错误出现,但这不起作用。
是否有任何/条件可以用来阻止此错误?在 Struts 2 中如何检查 jsp 中的会话是否有效?
I have an include jsp on all my pages which includes js files, css files, etc. This include jsp also refers to the session with "".
On the last page of my application, the action does a session.invalidate on the HttpSession object.
So when the last the last page of my application appears and runs the "", I get the following error since the session is invalidated
2011-10-19 10:30:59,134 WARN com.opensymphony.xwork2.ognl.OgnlValueStack - Caught an exception while evaluating expression '#session.user.isWhatever()' against value stack
java.lang.IllegalStateException: getAttribute: Session already invalidated
at org.apache.catalina.session.StandardSession.getAttribute(StandardSession.java:1062)
at org.apache.catalina.session.StandardSessionFacade.getAttribute(StandardSessionFacade.java:110)
at org.apache.struts2.dispatcher.SessionMap.get(SessionMap.java:165)
at ognl.MapPropertyAccessor.getProperty(MapPropertyAccessor.java:76)
I have tried "#session neq null" to stop the error from appearing but that doesn't work.
Is there anyway/condition to use to stop this error? How does one check if the session is valid in the jsp in Struts 2?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查是否存在已知会话值 - 在您的情况下为
#session.user
。您不必进行显式的空检查,IIRC(可能是错误的)。根据应用程序中的实际工作情况,您还可以检查isNew
,尽管这似乎没有必要。会话“永远”不会为空——除非明确指示,否则只需点击 JSP 页面就会创建一个会话。
Check for the presence of a known session value--in your case,
#session.user
. You shouldn't have to do an explicit null check, IIRC (could be wrong). Depending on how things are actually working in your app, you can also check forisNew
, although that seems like it shouldn't be necessary.The session will "never" be null--unless explicitly directed otherwise, just hitting a JSP page will create one.