i'm creating a web app using struts(controller) and jsp(presentation). jsp pages are using sessions, also they are crated using struts tiles like defining a layout and then insert that in any pages to provide a good appreance to app.
i created a filter named session only dofilter method is shown here
 RequestWrapper wrappedRequest = new RequestWrapper((HttpServletRequest) request);
        ResponseWrapper wrappedResponse = new ResponseWrapper((HttpServletResponse) response);
 
        doBeforeProcessing(wrappedRequest, wrappedResponse);
 
        Throwable problem = null;
 
        try {
           chain.doFilter(wrappedRequest, wrappedResponse);
        } catch (Throwable t) {
            // If an exception is thrown somewhere down the filter chain,
            // we still want to execute our after processing, and then
            // rethrow the problem after that.
            problem = t;
            t.printStackTrace();
        }

and this filter is mapped with url pattern "/views/*" as i want to check if there is a active session or not and forward to login page if session is not valid.
well, every thing worked for the very first time lanuching app only but later if any other request is made using url then that resource is displayed instead of forwarded to login page.

my web.xml file is
<context-param>
        <param-name>showList</param-name>
        <param-value>Morning,Afternoon,Evening,Night</param-value>
    </context-param>
    <filter>
        <filter-name>session</filter-name>
        <filter-class>filter.session</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>session</filter-name>
        <url-pattern>/views/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>
even if it is working for the very first request, sever log shows the following error
SEVERE: Exception initializing page context
java.lang.IllegalStateException: Cannot create a session after the response has been committed
at org.apache.catalina.connector.Request.doGetSession (Request.java:2734)
at org.apache.catalina.connector.Request.getSession(R equest.java:2244)
at org.apache.catalina.connector.RequestFacade.getSes sion(RequestFacade.java:899)
at org.apache.catalina.connector.RequestFacade.getSes sion(RequestFacade.java:911)
at javax.servlet.http.HttpServletRequestWrapper.getSe ssion(HttpServletRequestWrapper.java:238)
at javax.servlet.http.HttpServletRequestWrapper.getSe ssion(HttpServletRequestWrapper.java:238)
at org.apache.jasper.runtime.PageContextImpl._initial ize(PageContextImpl.java:146)
at org.apache.jasper.runtime.PageContextImpl.initiali ze(PageContextImpl.java:125)
at org.apache.jasper.runtime.JspFactoryImpl.internalG etPageContext(JspFactoryImpl.java:112)
at org.apache.jasper.runtime.JspFactoryImpl.getPageCo ntext(JspFactoryImpl.java:65)
at org.apache.jsp.views.admin.addnewshow_jsp._jspServ ice(addnewshow_jsp.java:57)
at org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:722)
at org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:419)
at org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:333)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:722)
at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:210)
at filter.session.doFilter(session.java:169) <--------------------------------------- refers to filter
at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:210)
at org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBas e.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(A ccessLogValve.java:563)
at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:399)
at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:317)
at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:204)
at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:182)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProce ssor.run(JIoEndpoint.java:311)
at java.util.concurrent.ThreadPoolExecutor.runWorker( ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
please help
regards