public class ValidateSessionTag extends TagSupport {
private static final long serialVersionUID = 1L;
private String client = "client";
private String page = "index.jsp";

/*
 * (non-Javadoc)
 * @see javax.servlet.jsp.tagext.Tag#doEndTag()
 */
public int doEndTag() throws JspException{
boolean valid = false;

HttpSession session = pageContext.getSession();
if(session.getAttribute(client) != null && session != null){
valid = true;
}

if(valid){
return EVAL_PAGE;
}
//the session value is losted
else {
try {
                                     //这里出错,出错信息见后面
pageContext.forward(page);
} catch (Exception e) {
CommonLogger.error(e.getMessage());
throw new JspException(e.toString());
}
return (SKIP_PAGE);
}
}

/*
 * (non-Javadoc)
 * @see javax.servlet.jsp.tagext.Tag#doStartTag()
 */
public int doStartTag() throws JspException {
return (SKIP_BODY);
} /**
 * @return Returns the client.
 */
public String getClient() {
return client;
} /**
 * @param client The client to set.
 */
public void setClient(String client) {
this.client = client;
} /**
 * @return Returns the page.
 */
public String getPage() {
return page;
} /**
 * @param page The page to set.
 */
public void setPage(String page) {
this.page = page;
}

/**
 * reset the value
 */
public void release() {
super.release();
this.client = MpfWebConstants.MPF_USER_INFO;
this.page = MpfWebConstants.MPF_LOGIN_PAGE;
}
}出错信息提示:
 java.lang.IllegalStateException: Cannot forward a response that is already committed请各位兄弟不惜赐教,谢谢

解决方案 »

  1.   

    这是一个逻辑问题,如果你JSP的if else流程中,同一条件下,可以有不同的跳转,就会报这个错,使一种流程中,只有唯一一种跳转就可以了,你把你的两个判断代码块,合并到一个大的if else中吧。
      

  2.   

    to terry_yip:please help me, how to modify it;thank you very much
      

  3.   

    pageContext.forward(page);
    我把这里的page 改成/contextPath/index.jsp, 出现空白页面,请再一次指教