Illegal State Exception with response.sendRedirect

Hi all,
When i am using response.sendRedirect(address), It is giving illegal state exception at few places. At few places it is working fine. I couldnt trace the reason.
I am using tomcat 4.1 with SSL configured for the server. Will session tracking effect response.sendRedirect(address)'s ability any way?
Can any body help me out...
Thanks in advance...
krish

I believe this quite often occurs when you have tried to send some kind of response already. I.E. you should not have sent anything to the client when you call this method so start by looking for any write's you have prior to the sendRedirect().
Ted.

Similar Messages

  • Illegal State Exception with Servlets

    Hi Friends,
    I am using RequestDispatcher to forwrd my request from one servlet to another
    Here's the code
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    public class TryServlet extends HttpServlet
    public void service(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
    try
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String url="jdbc:odbc:con";
    Connection con= DriverManager.getConnection(url,"scott","tiger");
    Statement stmt=con.createStatement();
    ResultSet rst=stmt.executeQuery("select * from Projects");
    response.setContentType("text/html");
    PrintWriter out=response.getWriter();
    while (rst.next())
    String firstname=rst.getString("PIN");
    String lastname=rst.getString("ProjectTitle");
    out.println("<p> Name:"+firstname+" "+lastname+"");
    con.close();
    RequestDispatcher rd=getServletContext().getNamedDispatcher("HelloServlet");
    rd.forward(request,response);
    return;
    catch(Exception e)
    e.printStackTrace();
    I m getting the error
    java.lang.IllegalStateException: Cannot forward after response has been committed
    i need to include the two rows of tables before i forwad the request to HelloServlet
    What needs to be done?
    thanx
    Pooja

    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    public class TryServlet extends HttpServlet
    public void service(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
    try
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String url="jdbc:odbc:con";
    Connection con= DriverManager.getConnection(url,"scott","tiger");
    Statement stmt=con.createStatement();
    ResultSet rst=stmt.executeQuery("select * from Projects");
    response.setContentType("text/html");
    PrintWriter out=response.getWriter();
    while (rst.next())
    String firstname=rst.getString("PIN");
    String lastname=rst.getString("ProjectTitle");
    out.println("<p> Name:"+firstname+" "+lastname+"");
    con.close();
    RequestDispatcher rd=getServletContext().getNamedDispatcher("HelloServlet");
    rd.forward(request,response);
    return;
    catch(Exception e)
    e.printStackTrace();
    please explain your problem for more details???

  • Illegal State Exception in JSP login

    I had a working log in/check password systems for a low security application. User types in username and password and this is sent to the checkpassword.jsp. Using Server variables I counted the number of attempts and if it was more than three, they were not allowed to try again that session. When I moved this page to newer version of Tomcat running in Apache rather than over IIS, my simple counting function no longer works and I can't for the life of me understand why I'm getting an Illegal State Exception with the following code:
    java.sql.ResultSet RS=statement.executeQuery("Select WUUSER, WUPWD FROM WEBUSER WHERE WUUSER='"+ (request.getParameter("username").toUpperCase()) + "' AND WUPWD= '" + (request.getParameter("password")) +"'");
    HttpSession ViewProtectedPage = request.getSession(true);
    HttpSession UserSession = request.getSession(true);
    if (RS.next())
    ViewProtectedPage.putValue("password","correct");
    //HttpSession UserSession = request.getSession(true);
    //allows username to be entered in upper or lower case
    UserSession.putValue("username",(request.getParameter("username")).toUpperCase());
    response.sendRedirect("tracking.jsp");
    else
    ViewProtectedPage.putValue("password","false");
    if (ViewProtectedPage.getValue("trycount")==null) {
    ViewProtectedPage.putValue("trycount","1");
    response.sendRedirect("loadtrackbadlogin.html");
    if (ViewProtectedPage.getValue("trycount")=="1") {
    ViewProtectedPage.putValue("trycount","2");
    response.sendRedirect("loadtrackbadlogin.html");
    if (ViewProtectedPage.getValue("trycount")=="2") {
    ViewProtectedPage.putValue("trycount","3");
    response.sendRedirect("loadtrackbadlogin.html");
    if (ViewProtectedPage.getValue("trycount")=="3") {
    response.sendRedirect("noentry.html");
    RS.close();
    It works fine if the user uses the proper username and password but crashes on me if they use the wrong info. I think it has something to do with my initialization of the user variables.

    I don't know that this is the root cause of your problem, but it certainly could be. When comparing two strings, you need to use the .equals() method, not ==.
    (except in the null case, where checking for null with == is perfectly okay).
    if (ViewProtectedPage.getValue("trycount").equals("1")
    ..etc
    Some other notes... use if/else if/else rather than a whole bunch of ifs, since all your statements are mutually exclusive. Maybe even put those lower ifs inside your outer "else" since you're obviously not going to reach them after a sendRedirect(). On that same note, place a return; after the sendRedirect() to state that the rest of the page need not be loaded/executed.

  • Illegal state exception in filters can any help me plzzzzzzz

    i want to check the clients status i mean whether the request is coming from new client or already using client , if clients request is new one then the filter has to redirect to some other login page and also if the request is asked to access the authenticated resource then also he want to force to redirect to login page.If the user is logged in and his session is not expired and if session is valid then he can access the requested url as per his role....can any one suggest the code plzzzzzzzzz
    here is my code but iam getting the illegal state exception as shown below...
    package uk.co.lex.interactive.authentication.action;
    import java.io.IOException;
    import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    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;
    public class AuthenticationFilter implements Filter {
    private FilterConfig filterConfig=null;
    HttpSession session=null;
         public void init(FilterConfig filterConfig) throws ServletException {
              //TODO Auto-generated method stub
              this.filterConfig=filterConfig;
              System.out.println("---Authentication filter initialized---");
         public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
              // TODO Auto-generated method stub
              HttpServletRequest req=(HttpServletRequest)request;
              HttpServletResponse res=(HttpServletResponse)response;
                   String reqSessId=req.getRequestedSessionId();
              if(reqSessId!=null)
                   {System.out.println("-------session is valid and the same client is using the resource111---");
                         if(req.isRequestedSessionIdValid())
                            System.out.println("-------session is valid and the same client is using the resource222---");
                            System.out.println("---requested sessid"+reqSessId);
                           if(req.isRequestedSessionIdFromCookie()||req.isRequestedSessionIdFromURL())
                                System.out.println("-------session is valid and the same client is using the resource333---");
              }else
              res.sendRedirect(req.getContextPath()+"/"+"checkUser.do");
                        System.out.println("------it is new session so it redirected to loginpage from authentication filter-------");
              else
                   res.sendRedirect(req.getContextPath()+"/"+"checkUser.do");
                   System.out.println("------it is new session so it redirected to loginpage from authentication filter-------");
              chain.doFilter(request,response);
         public void destroy() {
              // TODO Auto-generated method stub
              this.filterConfig=null;
              System.out.println("-----authentication filter destroyed---");
    11:03:18,693 ERROR [[action]] Servlet.service() for servlet action threw exception
    java.lang.IllegalStateException: Cannot create a session after the response has been committed
         at org.apache.catalina.connector.Request.doGetSession(Request.java:2195)
         at org.apache.catalina.connector.Request.getSession(Request.java:2017)
         at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:822)
         at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:833)
         at org.apache.struts.action.RequestProcessor.processLocale(RequestProcessor.java:621)
         at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:177)
         at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
         at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
         at uk.co.lex.interactive.authentication.action.AuthenticationFilter.doFilter(AuthenticationFilter.java:63)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
         at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
         at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
         at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
         at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
         at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
         at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
         at java.lang.Thread.run(Thread.java:595)

    I don't know that this is the root cause of your problem, but it certainly could be. When comparing two strings, you need to use the .equals() method, not ==.
    (except in the null case, where checking for null with == is perfectly okay).
    if (ViewProtectedPage.getValue("trycount").equals("1")
    ..etc
    Some other notes... use if/else if/else rather than a whole bunch of ifs, since all your statements are mutually exclusive. Maybe even put those lower ifs inside your outer "else" since you're obviously not going to reach them after a sendRedirect(). On that same note, place a return; after the sendRedirect() to state that the rest of the page need not be loaded/executed.

  • JComboBox Illegal state Exception problem

    Hello Everyone,
    I have the following code for creating a combobx in Eclipse. Now whenever eclipse reloads it gives an Illegal state exception error. When I remove the code and rewrite the same code it works fine. Any idea on how to fix this problem??
    Things are normal and there is no problem when I dont initialize the combobox.
    private JComboBox getJComboBoxNumOfSteps() {
           if (jComboBoxNumOfSteps == null) {
         String[] valStrings = { "1", "2", "3", "4", "5", "6", "7", "8", "9" ,"10","11","12","13","14","15","16","17"};
         jComboBoxNumOfSteps = new JComboBox(valStrings);
         jComboBoxNumOfSteps.setPreferredSize(new java.awt.Dimension(80,25));
         jComboBoxNumOfSteps.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent e) {
                                              Integer i = new Integer(jComboBoxNumOfSteps.getSelectedIndex()+1);
                              jTextArea.append(i.toString());
              jTextArea.append("\n");
            return jComboBoxNumOfSteps;
    }Thanx Amar

    Depends what context, and who's exception....
    I'll go with my best guess here though.
    You're using wait() and notify() and or notifyAll() with some threads. In this case the IllegalStateException is being thrown because you are calling one of these methods on an object you are not holding the lock for. Here are some good resources.
    Doug Lea's site.
    http://g.cs.oswego.edu
    and the book
    http://java.sun.com/docs/books/cp/
    if not,.... oh well, describe your problem better.
    -Spinoza

  • Please clarify on Illegal state exception

    Dear All pl explain Illegal state exception occurs in some program why. and what is the solution.

    Hi,
    This exception is thrown when a method is invoked at an illegal or inappropriate time or if the provider is not in an appropriate state for the requested operation.
    In servlets, for example, you have a method forward() in the RequestDispatcher class, which forwards the request to another resource for processing. This method should be called before the response is committed, else it throws IllegalStateException.

  • af:attribute Illegal state exception on tomcat

    I am getting Illegal state exception, when I use <af:attribute> referencing a row variable in treeTable :
    java.lang.IllegalStateException
         com.sun.faces.context.FacesContextImpl.assertNotReleased(FacesContextImpl.java:382)
         com.sun.faces.context.FacesContextImpl.getApplication(FacesContextImpl.java:120)
         oracle.adfinternal.view.faces.taglib.AttributeTag.doStartTag(AttributeTag.java:94)
         org.apache.jsp.ObjectList2_jspx._jspx_meth_af_attribute_0(ObjectList2_jspx.java:767)
         org.apache.jsp.ObjectList2_jspx._jspx_meth_af_commandLink_4(ObjectList2_jspx.java:749)
         org.apache.jsp.ObjectList2_jspx._jspx_meth_af_column_3(ObjectList2_jspx.java:543)
         org.apache.jsp.ObjectList2_jspx._jspx_meth_af_treeTable_0(ObjectList2_jspx.java:232)
         org.apache.jsp.ObjectList2_jspx._jspx_meth_af_form_0(ObjectList2_jspx.java:206)
         org.apache.jsp.ObjectList2_jspx._jspx_meth_afh_body_0(ObjectList2_jspx.java:188)
         org.apache.jsp.ObjectList2_jspx._jspx_meth_afh_html_0(ObjectList2_jspx.java:152)
         org.apache.jsp.ObjectList2_jspx._jspx_meth_f_view_0(ObjectList2_jspx.java:126)
         org.apache.jsp.ObjectList2_jspx._jspService(ObjectList2_jspx.java:97)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
         com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
         com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)
         oracle.adfinternal.view.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:134)
         com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
         com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
         com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
         javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
         oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl._doFilterImpl(AdfFacesFilterImpl.java:266)
         oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl.doFilter(AdfFacesFilterImpl.java:164)
         oracle.adf.view.faces.webapp.AdfFacesFilter.doFilter(AdfFacesFilter.java:87)
         oracle.adfinternal.view.faces.webapp.FacesFilter.doFilter(FacesFilter.java:89)
    If I use f:attribute, there is no exception, but also the attribute is not created. If I use f:attribute or af:atribute with a string value, it works OK.
    Here is my page:
    <?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="1.2"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:afh="http://xmlns.oracle.com/adf/faces/EA14/html"
    xmlns:af="http://xmlns.oracle.com/adf/faces/EA14" >
    <jsp:directive.page contentType="text/html;charset=utf-8"/>
    <f:view>
         <afh:html>
         <afh:head title="Main">
              <meta http-equiv="Content-Type"
                   content="text/html; charset=windows-1250"></meta>
         </afh:head>
         <afh:body>
              <af:form>
    <af:treeTable var="row" value="#{s.userObjectTreeModel}">
         <f:facet name="nodeStamp">
              <af:column>
                   <f:facet name="header">
                        <af:outputText value="User Objects" />
                   </f:facet>
                   <af:outputText value="#{row.item.userObjectName}" />
              </af:column>
         </f:facet>
         <af:column>
              <f:facet name="header">
                   <af:outputText value="Type" />
              </f:facet>
                   <af:outputText value="Micromart" rendered="#{row.item.micromart}" />
                   <af:outputText value="Group" rendered="#{row.item.userGroup}" />
                   <af:outputText value="Object" rendered="#{row.item.userObject}" />
         </af:column>
         <af:column>
              <f:facet name="header">
                   <af:outputText value="Status" />
              </f:facet>
                   <af:outputText value="#{row.item.status}" />
         </af:column>
         <af:column>
              <f:facet name="header">
                   <af:outputText value="Actions" />
              </f:facet>
              <af:commandLink text="Edit" actionListener="#{s.selectUserObject}"
                   rendered="#{row.item.userObject}">
                   <af:attribute name="item" value="#{row.item.userObjectName}" />
              </af:commandLink>          
         </af:column>
    </af:treeTable>
              </af:form>
         </afh:body>
         </afh:html>
    </f:view>
    </jsp:root>
    and here is server.xml :
    <?xml version = '1.0' encoding = 'ISO-8859-1'?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
    <!-- Faces API parameter -->
    <context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
    <!--param-value>server</param-value-->
    </context-param>
    <!-- ADF Faces by default uses an optimized client-side state saving
    mechanism. To disable that, uncomment the following -->
    <!--context-param>
    <param-name>oracle.adf.view.faces.CLIENT_STATE_METHOD</param-name>
    <param-value>all</param-value>
    </context-param-->
    <!-- Whether or not to turn on Oracle DMS metrics -->
    <!-- set to "true" to enable DMS metrics in an OC4J environment. -->
    <!-- Then you can go to
    http://<hostname>:<port>/<context-root>/servlet/Spy -->
    <context-param>
    <param-name>oracle.adf.view.faces.ENABLE_DMS_METRICS</param-name>
    <param-value>false</param-value>
    </context-param>
    <!-- Faces Filter -->
    <filter>
    <filter-name>faces</filter-name>
    <filter-class>oracle.adfinternal.view.faces.webapp.FacesFilter</filter-class>
    <init-param>
    <param-name>faces-servlet-url-pattern</param-name>
    <param-value>/faces/*</param-value>
    </init-param>
    </filter>
    <filter>
    <filter-name>adfFaces</filter-name>
    <filter-class>oracle.adf.view.faces.webapp.AdfFacesFilter</filter-class>
    </filter>
    <!-- Faces Filter Mappings -->
    <filter-mapping>
    <filter-name>faces</filter-name>
    <url-pattern>*.jspx</url-pattern>
    </filter-mapping>
    <filter-mapping>
    <filter-name>adfFaces</filter-name>
    <servlet-name>facesS</servlet-name>
    </filter-mapping>
    <!-- Faces Servlet -->
    <servlet>
    <servlet-name>facesS</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    </servlet>
    <!-- On some version of OC4J, the following is needed when using jsf 1.0 -->
    <!--servlet>
    <servlet-name>jsp</servlet-name>
    <servlet-class>oracle.jsp.runtimev2.JspServlet</servlet-class>
    <init-param>
    <param-name>tags_reuse_default</param-name>
    <param-value>none</param-value>
    </init-param>
    </servlet-->
    <!-- Faces Servlet Mappings -->
    <servlet-mapping>
    <servlet-name>facesS</servlet-name>
    <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <!-- Welcome Files -->
    <welcome-file-list>
    <welcome-file>index.jspx</welcome-file>
    </welcome-file-list>
    <!-- ADF Faces Tag Library -->
    <taglib>
    <taglib-uri>http://xmlns.oracle.com/adf/faces/EA14</taglib-uri>
    <taglib-location>/WEB-INF/af.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>http://xmlns.oracle.com/adf/faces/EA14/html</taglib-uri>
    <taglib-location>/WEB-INF/afh.tld</taglib-location>
    </taglib>
    <!-- Faces Core Tag Library -->
    <taglib>
    <taglib-uri>http://java.sun.com/jsf/core</taglib-uri>
    <taglib-location>/WEB-INF/jsf_core.tld</taglib-location>
    </taglib>
    <!-- Faces Html Basic Tag Library -->
    <taglib>
    <taglib-uri>http://java.sun.com/jsf/html</taglib-uri>
    <taglib-location>/WEB-INF/html_basic.tld</taglib-location>
    </taglib>
    <!-- Survey Demo (Custom) Tag Library -->
    <taglib>
    <taglib-uri>http://xmlns.oracle.com/adf/faces/EA14/demo</taglib-uri>
    <taglib-location>/WEB-INF/survey.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>http://xmlns.oracle.com/adffacesdemo</taglib-uri>
    <taglib-location>/WEB-INF/uixdemo.tld</taglib-location>
    </taglib>
    </web-app>
    I use Tomcat 5.0.18 (embeded in Eclipse for web) and ADF Faces ea14 (with ea13 was the same problem.)
    Thanks for any hints...

    When I refresh the page after this exception, the content is displayed correctly. When I make new request on this page, I get new Illegal state exception, after the refresh the content is displayed correctly again ...

  • Strange behaviour with response.sendRedirect

    I have a strange problem with response.sendRedirect
    --The following is part of a class that implements Filter (its main task is to check for authentication)
    The redirect method hresponse.sendRedirect doesnot work (so i had to make it a forward method using dispatcher)
    The second one however, works!!!! how could that be?
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
          throws ServletException, IOException
               HttpServletRequest h =(HttpServletRequest)request;
               HttpServletResponse hresponse = (HttpServletResponse)response;
               ServletContext application = config.getServletContext();
            Connection con = (Connection)application.getAttribute("connection");
               String username = (String)h.getSession().getAttribute("user");
               String credentials = (String)h.getSession().getAttribute("cred");
               PrintWriter out = response.getWriter();
               if (con != null)
                   try
                   Statement     stmt = con.createStatement(
                        ResultSet.TYPE_SCROLL_INSENSITIVE,
                         ResultSet.CONCUR_READ_ONLY);
              ResultSet rs;
                        rs = stmt.executeQuery("SELECT * FROM member WHERE username = '"+ username
                                                                                              +"' AND password ='" + credentials+ "' ");
                        if(rs.next() && rs != null)
         String path = h.getServletPath() ;
              h.getSession().setAttribute("user", username);
              h.getSession().setAttribute("cred", credentials);
              //RequestDispatcher dispatcher = config.getServletContext().getRequestDispatcher(path);
    //dispatcher.forward(request,response);
              String s = hresponse.encodeURL("http://localhost:8080/support/mtext.html");
                   //out.println(s);
                   hresponse.sendRedirect(s);
                        else
         String path = h.getRequestURI();
         String query = h.getQueryString();
    //     String query_sub = query.substring(0,equalPos);
         if (!query_sub.equals("threadID"))
              out.println("error occured");
                   else
              if(query == "null")
                   query="";
              else
                   query= "?" + query;
                   hresponse.sendRedirect(hostPath + "/support/index2.jsp?"+
                   "forward="+h.getRequestURI() + query );
                   }

    Hi,
    response.sendRedirect() may throw an IOException if URL not found.So you have to write throws or try & catch.
    Ajay.

  • Illegal State Exception ; Resource resolver already closed

    Hi
         In my component I have a page resource. When I am trying to get the image resource of the same as below it is throwing me an Illegal State exception
    Resource resource = page.getContentResource("image");
    My error stack trace is as follows
                     Eventhough i am not closing any resource ; it is giving me illegal state exception for the resource. Please help me in finding a solution for this.
    Thanks
    Veena

    Are you calling the right path?
    The call to page.getContentResource("image") will end up calling the following:
    resource.getResourceResolver().getResource(resource, “jcr:content/image”);

  • Weblogic 6.0 (SP2) generates incorrect java code for JSP with response.sendRedirect()

              Hi,
              Here are the steps to reproduce the problem with the examplesWebApp application
              bundled with wlserver6.0(sp2):
              Product: Weblogic server 6.0 (sp2)
              Browser: IE 5.0
              1. Add index.jsp as the welcome file in WEB-INF/web.xml
              2. Create index.jsp as below:
              <%
              response.sendRedirect("index.html");
              return;
              %>
              <html>
              <head>
              <title>Index JSP file</title>
              </head>
              <body>
              <font color="red">This is index.jsp file </font>
              </body>
              </html>
              3. Create index.html as below:
              <html>
              <head>
              <title>Index HTML file</title>
              </head>
              <body>
              <font color="red">This is index.html file </font>
              </body>
              </html>
              4. Run the examples server and make sure examplesWebApp is deployed on the examples
              server using the console
              5. Access the URL http://localhost:7001/examplesWebApp
              The page will display a compilation error as below:
              C:\bea\wlserver6.0\config\examples\applications\examplesWebApp\WEB-INF\_tmp_war_examplesServer_examplesServer_examplesWebApp\jsp_servlet\_index.java:89:
              unreachable statement
              out.print("\r\n<html>\r\n<head>\r\n<title>Simple html</title>\r\n</head>\r\n<body>\r\n<font
              color=\"red\">This is index.jsp page</font>\r\n</body>\r\n</html>\r\n");
              ^
              and a look at the generated java code for index.jsp (_index.java) will reveal
              the erroneous code snippet below in the jsp service method:
              try { // error page try block
              //[ /index.jsp; Line: 1]
              response.sendRedirect("index.html"); //[ /index.jsp; Line: 2]
              return; //[ /index.jsp; Line: 3]
              out.print("\r\n<html>\r\n<head>\r\n<title>Simple html</title>\r\n</head>\r\n<body>\r\n<font
              color=\"red\">This is index.jsp page</font>\r\n</body>\r\n</html>\r\n");
              } catch (Exception __ee) {
              while (out != null && out != _originalOut) out = pageContext.popBody();
              pageContext.handlePageException(__ee);
              The above web application works fine in Tomcat 3.2.X environment. The Weblogic
              server 6.0 servlet engine should not generate the "out.println()" corresponding
              to the html section of index.jsp. The moment it sees the "return", it should stop
              processing further.
              Can someone from Weblogic support team please verify this and let me know when
              this bug will be fixed?
              One interesting thing I noticed was when we last tried weblogic 6.0 at its beta
              stage, it worked fine after we put in a special patch jar file called "redirectfix.jar"
              we received from weblogic team but somehow it got re-introduced by the time it
              was released!!
              We are planning to migrate our product from tomcat 3.2.x to weblogic 6.0. Our
              product has a lot of pages with such conditional {response.sendRdirect("page.jsp");return;}
              blocks. We would really appreciate a faster response form weblogic team.
              Thanks in advance.
              sam...
              Sam Palanisamy
              Senior Software Engineer
              Manage.com
              2345 N. First Street First Floor
              San Jose CA 95131
              

    Why should it stop when it sees a return? Is that in the spec?
              Peace,
              Cameron Purdy
              Tangosol Inc.
              << Tangosol Server: How Weblogic applications are customized >>
              << Download now from http://www.tangosol.com/download.jsp >>
              "Sam Palanisamy" <[email protected]> wrote in message
              news:[email protected]...
              >
              > Hi,
              >
              > Here are the steps to reproduce the problem with the examplesWebApp
              application
              > bundled with wlserver6.0(sp2):
              >
              > Product: Weblogic server 6.0 (sp2)
              > Browser: IE 5.0
              >
              > 1. Add index.jsp as the welcome file in WEB-INF/web.xml
              >
              > 2. Create index.jsp as below:
              > <%
              > response.sendRedirect("index.html");
              > return;
              > %>
              > <html>
              > <head>
              > <title>Index JSP file</title>
              > </head>
              > <body>
              > <font color="red">This is index.jsp file </font>
              > </body>
              > </html>
              >
              > 3. Create index.html as below:
              > <html>
              > <head>
              > <title>Index HTML file</title>
              > </head>
              > <body>
              > <font color="red">This is index.html file </font>
              > </body>
              > </html>
              >
              > 4. Run the examples server and make sure examplesWebApp is deployed on the
              examples
              > server using the console
              >
              > 5. Access the URL http://localhost:7001/examplesWebApp
              >
              > The page will display a compilation error as below:
              >
              C:\bea\wlserver6.0\config\examples\applications\examplesWebApp\WEB-INF\_tmp_
              war_examplesServer_examplesServer_examplesWebApp\jsp_servlet\_index.java:89:
              > unreachable statement
              > out.print("\r\n<html>\r\n<head>\r\n<title>Simple
              html</title>\r\n</head>\r\n<body>\r\n<font
              > color=\"red\">This is index.jsp page</font>\r\n</body>\r\n</html>\r\n");
              > ^
              >
              > and a look at the generated java code for index.jsp (_index.java) will
              reveal
              > the erroneous code snippet below in the jsp service method:
              >
              > try { // error page try block
              >
              > //[ /index.jsp; Line: 1]
              > response.sendRedirect("index.html"); //[ /index.jsp; Line: 2]
              > return; //[ /index.jsp; Line: 3]
              > out.print("\r\n<html>\r\n<head>\r\n<title>Simple
              html</title>\r\n</head>\r\n<body>\r\n<font
              > color=\"red\">This is index.jsp page</font>\r\n</body>\r\n</html>\r\n");
              > } catch (Exception __ee) {
              > while (out != null && out != _originalOut) out =
              pageContext.popBody();
              > pageContext.handlePageException(__ee);
              > }
              >
              > The above web application works fine in Tomcat 3.2.X environment. The
              Weblogic
              > server 6.0 servlet engine should not generate the "out.println()"
              corresponding
              > to the html section of index.jsp. The moment it sees the "return", it
              should stop
              > processing further.
              >
              > Can someone from Weblogic support team please verify this and let me know
              when
              > this bug will be fixed?
              >
              > One interesting thing I noticed was when we last tried weblogic 6.0 at its
              beta
              > stage, it worked fine after we put in a special patch jar file called
              "redirectfix.jar"
              > we received from weblogic team but somehow it got re-introduced by the
              time it
              > was released!!
              >
              > We are planning to migrate our product from tomcat 3.2.x to weblogic 6.0.
              Our
              > product has a lot of pages with such conditional
              {response.sendRdirect("page.jsp");return;}
              > blocks. We would really appreciate a faster response form weblogic team.
              >
              > Thanks in advance.
              > sam...
              > Sam Palanisamy
              > Senior Software Engineer
              > Manage.com
              > 2345 N. First Street First Floor
              > San Jose CA 95131
              >
              >
              

  • TABLE ILLEGAL STATEMENT  error with MODIFY command

    Hi gurus,
    i want you to inform me about table illegal statement error. The error occurs when i use modify as below.
    loop at itab.
       select .......
             where xxx eq itab-xxxx.
           MODIFY itab.
      endselect.
    endloop.
    i know that i have to give the sy-tabix as INDEX parameter to the modify command. but i want to know why i have to do this?
    cause when i debug, i follow the sy-tabix field and it have not a change in select endselect.
    may the reason of the error about cursor in select and cursor effects modify command?
    or why?
    Thx,

    Hello,
    I guess this is because your MODIFY statement is inside the SELECT ... ENDSELECT & not inside the LOOP ... ENDLOOP.
    SAP documentation says:
    Within a LOOP loop, the INDEX addition can be ommitted. In this case the current table line of the LOOP loop is changed.
    You have to change the coding:
    DATA: v_index TYPE i.
    loop at itab.
    v_index = sy-index.
    select .......
    where xxx eq itab-xxxx.
    MODIFY itab INDEX v_index.
    endselect.
    endloop.
    BR,
    Suhas
    PS: The coding practice followed is not very performance oriented as well. May be you should have a look around in some blogs, wikis in SCN & change the code accordingly.
    Edited by: Suhas Saha on Nov 19, 2009 9:41 AM

  • Strange Illegal State Exception

    Hello all,
    I've been writing a large webapp for a while and have suddenly started getting this exception. It turns up in the web server logs, occurs in the middle of a loop, and although all exceptions in my servlet are caught and forwarded to a generic error page, this exception causes the output to stop - leaving just the already-output HTML on the page. I guess this is because it's a runtime exception.
    I know this can occur by calling getWriter() and getOutputStream() in the same servlet, but I've done nothing except println() on my PrintWriter after using getWriter() to retrieve it.
    Anyone got any ideas on why this might occur?
    Thanks!
    Gemma

    Here's the loop in which the error occurs:
               for(int i=0;i<theVector.size();i++)
              CustomObject temp = (CustomObject)theVector.elementAt(i);
              if(user.hasMultipleAttributes())
                if(i==0)
                  out.println("<tr><td colspan=\"6\">For <b>" + temp.getCountry() + "</b></td></tr><tr><td colspan=\"6\"><br></td></tr>");
                else
                  if(!temp.getCountry().equals(lastCountry))
                    out.println("<tr><td colspan=\"6\">For <b>" + temp.getCountry() + "</b></td></tr><tr><td colspan=\"6\"><br></td></tr>");
                lastCountry = temp.getCountry();
              out.println("<tr><td>" + temp.getStory() + "</td>");
              out.println("<td>" + temp.getLanguage() + "</td>");
              if(currentUser.hasMultipleAttributes())
                out.println("<td>" + temp.getCountry() + "</td>");
              out.println("<td>" + temp.getRequestDate() + "</td>");
              out.println("<td>" + temp.getPublishDate() + "</td>");
              if(temp.isComplete())
                out.println("<td><img src=\"" + URLContainer.getTickImageURL() + "\"></img></td>");
              else
                out.println("<td><form method=\"post\" action=\"" + URLContainer.getCompleteStoryDetailsURL() + "\"><input type=\"hidden\" name=\"storyname\" value=\"" + temp.getStoryName() + "\"><input type=\"hidden\" name=\"language\" value=\"" + temp.getLanguage() + "\"><input type=\"hidden\" name=\"country\" value=\"" + temp.getCountry() + "\"><input type=\"submit\" value=\"Complete Usage Details\"></form></td>");
              out.println("</tr>");
              CustomObject temp2 = (CustomObject)theVector.elementAt(i+1);
              if(!lastCountry.equals(temp2.getCountry()))
                out.println("<tr><td colspan=\"6\"><br></td></tr>");
               } I can't see anything in here which would cause such an error. I don't pass the PrintWriter (out) anywhere... I don't set the buffer size and I don't believe that the PrintWriter is returned in autoFlush mode (not 100% sure though).
    For redirects, I tend to use HttpServletResponse.sendRedirect().
    Thanks
    Gemma

  • How to avoid illegal state exception in jsp/servlets

    Hi,
    Am working on jsps and servlets ,some times am getting Illegalstateexception,in what situations we will get this exception,can any one tell clearly about this exception..
    mani

    Since there's no other real supporting information you have out there, I can only take a wild stab at this...
    My guess is that you're trying to invoke methods on the server with your jsp code that isn't allowed. For example, I often work with a PDM software that will throw Illegalstateexceptions when I try to modify objects in the system that are not checked out. More than a java thing, this might be an issue with the servlets you're using. If your servlet is being provided by a vendor, you might want to check up on their API for more information about such an error occuring, or consult their technical support, if such a group exists.
    If this is your own servlet, I would suggest making sure that the methods you're trying to invoke are available for the servlet to invoke, which would also cause that exception.

  • Illegal state exception

    I am often getting the exception shown below
    javax.jms.IllegalStateException: Operation not allowed
    [22/Jun/2006:17:08:15] WARNING (10553): CORE3283: stderr:      at com.sun.enterprise.jms.SessionWrapperEjb.commit(SessionWrapperEjb.java:55)
    [22/Jun/2006:17:08:15] WARNING (10553): CORE3283: stderr:      at com.transversalnet.grid.util.QueueHandler.pushMessage(QueueHandler.java:362)
    [22/Jun/2006:17:08:15] WARNING (10553): CORE3283: stderr:      at com.transversalnet.grid.util.QueueHandler.pushMessageForSending(QueueHandler.java:118)
    [22/Jun/2006:17:08:15] WARNING (10553): CORE3283: stderr:      at com.transversalnet.grid.module.user.UserUtil.pushToOriginatingServer(UserUtil.java:464)
    [22/Jun/2006:17:08:15] WARNING (10553): CORE3283: stderr:      at com.transversalnet.grid.handler.user.MsgUserHandler.createUser(MsgUserHandler.java:290)
    [22/Jun/2006:17:08:15] WARNING (10553): CORE3283: stderr:      at com.transversalnet.grid.handler.user.MsgUserHandler.handle(MsgUserHandler.java:183)
    [22/Jun/2006:17:08:15] WARNING (10553): CORE3283: stderr:      at com.transversalnet.grid.handler.user.UserHandler.handle(UserHandler.java:43)
    [22/Jun/2006:17:08:15] WARNING (10553): CORE3283: stderr:      at com.transversalnet.grid.ejb.processor.ProcessorBean.onMessage(ProcessorBean.java:83)
    [22/Jun/2006:17:08:15] WARNING (10553): CORE3283: stderr:      at com.sun.ejb.containers.MessageBeanContainer.onMessage(MessageBeanContainer.java:857)
    [22/Jun/2006:17:08:15] WARNING (10553): CORE3283: stderr:      at com.sun.ejb.containers.MessageBeanListenerConcurrent.onMessage(MessageBeanListenerConcurrent.java:20)
    [22/Jun/2006:17:08:15] WARNING (10553): CORE3283: stderr:      at com.sun.messaging.jmq.jmsclient.ServerSessionRunner.onMessage(ServerSessionRunner.java:139)
    [22/Jun/2006:17:08:15] WARNING (10553): CORE3283: stderr:      at com.sun.messaging.jmq.jmsclient.ServerSessionRunner.run(ServerSessionRunner.java:105)
    [22/Jun/2006:17:08:15] WARNING (10553): CORE3283: stderr:      at com.sun.messaging.jmq.jmsclient.SessionImpl.run(SessionImpl.java:2313)
    [22/Jun/2006:17:08:15] WARNING (10553): CORE3283: stderr:      at com.sun.enterprise.jms.SessionWrapperBase.run(SessionWrapperBase.java:199)
    [22/Jun/2006:17:08:15] WARNING (10553): CORE3283: stderr:      at com.iplanet.ias.ejb.containers.IASServerSessionImpl.run(IASServerSessionImpl.java:191)
    Any idea why it is happening
    Suneesh

    It appears that you are calling commit in your Message
    Driven bean ...
    This is not allowed per the EBJ specification (the container
    is responsible for committing or rolling back the action)

  • How to avoid Illegal State Exception?

    Im using struts and develop in J2EE. My action class calls the ejb and returns to the actionClass and then to the jsp. This works once and the second time , i get IllegalStateException. But without recompiling when i restart ,my jboss and preform the previous activity , it works fine!!
    Does have an explanation and provide a solution?
    Thanks

    This is error snippet obtained!
    2007-10-09 10:47:05,984 WARN [org.apache.struts.action.RequestProcessor] Unhandled Exception thrown: class java.lang.IllegalStateException
    2007-10-09 10:47:05,984 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[].[action]] Servlet.service() for servlet action threw exception
    java.lang.IllegalStateException: No transaction.
         at org.jboss.tm.TxManager.rollback(TxManager.java:331)
         at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.rollback(ServerVMClientUserTransaction.java:134)
         at com.modulbio.struts.actionclasses.experiment.CreatePasteurExpPlatesAction.execute(CreatePasteurExpPlatesAction.java:463)
         at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
         at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
         at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
         at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
         at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
         at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
         at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
         at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:407)
         at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
         at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
         at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
         at java.lang.Thread.run(Thread.java:595)

Maybe you are looking for

  • Can I let my daughter use the things in my itune account in hers?

    I just bought my daughter an ipod touch and I want to load it with some of the things that I have purchased from itunes for my iphone. She has a separate itunes account with her old ipod. Is there a way to let her use the things from my itunes librar

  • How do I fix font problems in InDesign?

    Fonts are not displaying correctly in InDesign . .  . Exporting to PDF produces distorted fonts. I have tried with Helvetica and Helvetica Nue. I am not using third party font software . . I am on OSC Maverics running Indesign CC. Also some low res j

  • Problem with SAX parser with String format

    hi, all I have the next problem: I try to parse xml file with success, I write next code: ==================== my_class saxUms = new my_class(); File file = new File( "c:\\my_try_Response.xml" ); InputSource src1 = new InputSource( new FileInputStrea

  • Airplay not detected in windows 7 itunes.

    Airplay not detected on windows itunes even after windows update. Security & windows firewall not an issue. Please assist in re-installing the airplay option in my windows 7 itunes.

  • HT201412 iPad 2 update to iOS6.1 fails and will not restore

    Tried to update one of our ad 2 to iOS 6.1. The update failed and left a screen with a picture of a USB cable with iTunes logo displayed. Tried the restore procedure three times. Each fails with an error about download file being corrupt.