illegal state exception

hi friends,

whenever i use filters i am getting this exception. please help me here. thanks

code]HTTP Status 500 -

--

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.IllegalStateException: getOutputStream() has already been called for this response

org.apache.coyote.tomcat5.CoyoteResponse.getWriter(CoyoteResponse.java:599)

org.apache.coyote.tomcat5.CoyoteResponseFacade.getWriter(CoyoteResponseFacade.java:163)

org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:122)

org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:115)

org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:190)

org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:115)

org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)

org.apache.jsp.protected_.hello_jsp._jspService(hello_jsp.java:80)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

filters.ActionByTimeFilter.doFilter(ActionByTimeFilter.java:100)

note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.

--

Apache Tomcat/5.0.28[/code]

i am always getting this error

[1784 byte] By [bobza] at [2007-10-3 0:48:40]
# 1

> java.lang.IllegalStateException: getOutputStream()

> has already been called for this response

You cannot call getOutputStream twice or if getWriter has already been called. Also you cannot use RequestDispatcher's forward method if either getOutputStream or getWriter has been called.

YoGeea at 2007-7-14 17:43:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
i have not used getoutputstream at all and i have not forwarded , i just used include method of requestdispatcher
bobza at 2007-7-14 17:43:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
> i have not used getoutputstream at all and i have not> forwarded , i just used include method of> requestdispatcherI think you'll find include has the same caveat as forward and getOutputStream or getWriter has already been called for the response.
YoGeea at 2007-7-14 17:43:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

my filter file ...i never used anything as we discussed above

package filters;

import java.io.IOException;

import java.util.HashSet;

import java.util.StringTokenizer;

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 org.apache.log4j.Logger;

/**

* Mantis issue 1762 : To implement the warning before logging out functionality.

* @author psbabu

*/

public class ActionByTimeFilter implements Filter {

private final static String DEFAULT_SCRIPT_URL = "/jscript/throwpopup.js";

private final static String DELIMITER_CHAR = ",";

//private final static Logger log = Logger.getLogger(ActionByTimeFilter.class);

private FilterConfig config;

private String scriptUrl;

private HashSet exclusivePages;

/**

* @param DEFAULT_SCRIPT_URL

* @param DELIMITER_CHAR

* @param log

* @param config

* @param scriptUrl

* @param exclusivePages

*/

public void init(FilterConfig config) throws ServletException {

//log.info("Entering a method");

this.config = config;

String scriptUrl = this.config.getInitParameter("checktimer-script-url");

//log.assertLog((scriptUrl!=null), "String scriptUrl = null");

this.scriptUrl = (scriptUrl != null) ? scriptUrl : DEFAULT_SCRIPT_URL;

/**

* @param exclusiveListPages specifies the param value of "exclusive-pages-of-checkingtimer"

*/

///String exclusiveListPages = this.config.getInitParameter("exclusive-pages-of-checkingtimer");

//log.assertLog((exclusiveListPages!=null), "String exclusiveListPages = null");

//if (exclusiveListPages != null && exclusiveListPages.length() > 0) {

//this.exclusivePages = populateExclusivePages(exclusiveListPages);

//}

//log.debug("Initialize parameters in web.xml: checktimer-script-url = " + scriptUrl

//+ "; exclusive-pages-of-checkingtimer.size = " + exclusivePages);

/*if (log.isInfoEnabled()) {

log.info("Setting initialize parameters: checktimer-script-url = " + this.scriptUrl

+ "; exclusive-pages-of-checkingtimer.size = " + this.exclusivePages.size());

log.info("Exiting the method");

} */

}

public void doFilter(ServletRequest req, ServletResponse res,

FilterChain chain) throws IOException, ServletException {

HttpServletRequest httpReq = null;

if (req instanceof HttpServletRequest) {

httpReq = (HttpServletRequest) req;

String status = (String) httpReq.getAttribute("checktimerStatus");

RequestDispatcher rd = httpReq.getRequestDispatcher(scriptUrl);

rd.include(req, res);

httpReq.setAttribute("checktimerStatus", "inserted");

//log.debug("The script throwpopup.js "

//+ (String) req.getAttribute("servletname"));

} else {

//log.warn("The check timer filter is runnig out of servlet context");

}

chain.doFilter(req, res);

}

public void destroy() {

this.config = null;

this.exclusivePages = null;

}

/*private HashSet populateExclusivePages(String exclusiveListPages) {

HashSet exclusiveSet = null;

if (exclusiveListPages != null && exclusiveListPages.length() > 0) {

exclusiveSet = new HashSet();

//log.assertLog((exclusiveSet!=null), "HashSet exclusiveSet = null");

StringTokenizer tokenizer = new StringTokenizer(exclusiveListPages.trim(), DELIMITER_CHAR);

//log.assertLog((tokenizer!=null), "StringTokenizer tokenizer = null");

while (tokenizer.hasMoreTokens()) {

exclusiveSet.add(tokenizer.nextToken());

}

}

return exclusiveSet;

}*/

}

bobza at 2007-7-14 17:43:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
You need to call setAttribute before include is called and then return after include is called. Otherwise you are still calling doFilter every time which probably does its own forward.
YoGeea at 2007-7-14 17:43:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
i totally removed setattribute, even now , am getting the same error
bobza at 2007-7-14 17:43:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
> i totally removed setattribute, even now , am getting> the same errorSo did you put a return; after you call include? The error is with doFilter probably because you are calling include and then calling doFilter.
YoGeea at 2007-7-14 17:43:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
the same sample is working fine in weblogic 8.1
bobza at 2007-7-14 17:43:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
do u know the reason ?
bobza at 2007-7-14 17:43:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...