public class Actions extends Action {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
ActionForms actionForms = (ActionForms) form;// TODO Auto-generated method stub
HttpSession session=request.getSession();
String type="";
type=(String)request.getParameter("type");
if("large".equals(type))
{
ArrayList arrayList=(ArrayList)BusImpl.busCheck();
request.setAttribute("busList", arrayList);
return mapping.findForward("large");
}
if("user".equals(type))
{
String userName=actionForms.getUserName();
String passWord=actionForms.getPassWord();
if(UserImpl.login(userName, passWord))
{
session.setAttribute("flag", "ok");
return mapping.findForward("check");
}
}
if("logout".equals(type))
{
if(session.getAttribute("flag")!=null)
{
session.invalidate();
}
}
if(session.getAttribute("flag")!=null)
{
int id=actionForms.getId();
if(id==0){}
else
{
BusImpl.busChange(id);
}
ArrayList arrayList=(ArrayList)BusImpl.busCheck();
request.setAttribute("busList", arrayList);
return mapping.findForward("check");
}
return mapping.findForward("large");
}
}
以上是Action代码,注销以超链接“?”传type值为logout,但一注销就出下列错误:
javax.servlet.ServletException: java.lang.IllegalStateException: getAttribute: Session already invalidated
------解决方案--------------------------------------------------------
在你注销时
------解决方案--------------------------------------------------------
if("logout".equals(type))
{
if(session.getAttribute("flag")!=null)
{
session.invalidate();
}
}
if(session.getAttribute("flag")!=null)
{
如果type等于logout的话就会注销,注销之后又执行下面的session.getAttribute("flag"),所以报错session已经失效
------解决方案--------------------------------------------------------
刚才没看清你代码。。。
开头好像获取 session 了。
既然是getAttribute的时候失效,那可能就在这个周期前出问题了。
如果只是判断标志位的话而且用了struts,直接 request.setAttribute("flag", "ok");试试吧。