EJB design: java.lang.IllegalStateException: Cannot forward after response h

  1. I get this exception when i m trying to forward or redirect to an error page..pls suggest...working obn this for 2 long.I tried reqdispatecher.fwd and also res.sendRedirect..but always get illegal state excpetion. package com.ibasis.dss.web.filter; import java.util.Calendar; import java.util.GregorianCalendar; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * This class handles filter requests. */ public class RedirectFilter implements Filter { private static final Log log = LogFactory.getLog(RedirectFilter.class); private FilterConfig config; String url ="redirectError.jsp"; public void init(FilterConfig filterConfig) throws ServletException { this.config = filterConfig; } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws java.io.IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse res = (HttpServletResponse) response; try { HttpSession session = req.getSession(); String start = (String) session.getServletContext().getInitParameter("Startuptime"); //log.debug("Start is.."+start); String end = (String)session.getServletContext().getInitParameter("Endtime"); if(isApplicationDisabled(start,end)) { RequestDispatcher rd = req.getRequestDispatcher(url); rd.forward(req, res); } else { chain.doFilter(request, response); // Permission granted } } catch(Exception e) {e.printStackTrace();} } public static boolean isApplicationDisabled(String start, String end) { double startValue = Double.parseDouble(start) ; double endValue = Double.parseDouble(end); Calendar cal = new GregorianCalendar(); int getHrs=cal.get(Calendar.HOUR_OF_DAY); int getMins = cal.get(Calendar.MINUTE); double mins = (double)getMins/60; double time = getHrs+mins; if(time >= startValue && time <= endValue) { //log.debug("COndition is.."+time); return true; } else { return false; } } public void destroy() { this.config = null; } }

    Threaded Messages (3)

  2. This is the JSP fo r teh above metioned servlet code.Thx <%@ include file="/common/taglibs.jsp"%> Server Maintenance
  3. Re: Illegal state exception[ Go to top ]

    It worked for me. See "How can I create a maintenance window for my web app?"
  4. illegal state[ Go to top ]

    The getRequestDispatcher(String path) method of javax.servlet.ServletContext interface cannot accepts relative paths. All path must sart with a "/" and are interpreted as relative to curent context root.