我正在使用< bean:write />
成功从会话打印JSP上的某些值。但是在提交页面后,如果我回来(会话到期后)并刷新页面,则会在页面上打印完整的strack trace;
< session attribute name> not found in session scope.
为了避免这种情况,我做了两件事。但没有什么对我有用。
< bean:write />
< logic:empty />
< session attribute name>
的值是否为空。如果是这样,我将其重定向到错误页面。如果我在请求中添加属性而不是会话,我面临同样的问题。
< request attribute name> not found in request scope.
JSP中的代码检查会话
HttpSession sess = request.getSession(false);
if (sess == null) {response.sendRedirect("errorpg.jsp");}
else{
String sessionId_Logon = (String) sess.getAttribute("attrName");
if(sessionId_Logon == null)
{
response.sendRedirect("errorpg.jsp");
}
}
我知道“其他”块的感觉较少。我也曾单独尝试过。
答案 0 :(得分:0)
我更倾向于在页面上检查会话是否有效,然后通知用户它是否已过期。有关如何做的一些想法,请参阅this thread或this one之类的内容。
答案 1 :(得分:0)
嘛!我猜我发现了这个问题。 < bean:write />
之前已经编译过了。因此,我的外部检查会议更少。
现在我有2个解决方案;
< bean:write />
。相反,我可以使用scriptlet 我正在使用第二个。
答案 2 :(得分:0)
可能这可以帮到你.... 它与我合作..
<logic:empty name="employee" scope="session">
<jsp:forward page="LoginScreen.do"/>
</logic:empty>
欢迎先生<bean:write name="employee" scope="session"/ >