You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Łukasz Lenart <lu...@googlemail.com> on 2011/07/26 07:34:29 UTC

Re: SEVERE: Servlet.service() for servlet default threw exception, java.lang.IllegalStateException

2011/7/25 Emi Lu <em...@encs.concordia.ca>:
>  <filter-mapping>
>      <filter-name>struts</filter-name>
>      <url-pattern>/*</url-pattern>
>      <dispatcher>REQUEST</dispatcher>
>      <dispatcher>INCLUDE</dispatcher>
>   </filter-mapping>

Did you try to remove these dispatcher params ? Or add FORWARD ?


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
Warszawa JUG conference - Confitura http://confitura.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: SEVERE: Servlet.service() for servlet default threw exception, java.lang.IllegalStateException

Posted by Dave Newton <da...@gmail.com>.
My first guess would be that it's an issue with two different things writing
to the output stream, that often causes illegal state exceptions. Can you do
it in such a way that errors are handled by a result instead off in the
action and see what that does?

Dave
 On Jul 26, 2011 10:13 AM, "Emi Lu" <em...@encs.concordia.ca> wrote:
> Hi Łukasz,
>
>>> tomcat6 + struts2.2.3 + tiles2.2.2 + springframework3.05 + displaytag
1.2.
>>
>> Could you list the jars in WEB-INF/lib ? It looks like you're mixing
>> different version of jars.
>
> It seems that I found the problem. When I commented out ajax section
> "onclick="return ajax_check_search_table('check_search_opr')"", the
> error is gone. But I need ajax check support.
>
> Do you know why ajax and which parts in ajax cause this exception?
>
> Thanks a alot!
> Emi
>
> ----
>
> form.jsp
> ===========
> ....
> <s:submit value="Login" onclick="return
> ajax_check_search_table('check_search_opr')" action="method1ActionView" />
> .....
> <script type="text/javascript">
> function ajax_check_search_table(opr_name)
> {
> var str = $("form").serialize(); //http://api.jquery.com/serialize/
> var return_yn = false;
>
> $.ajax({
> async: false,
> url : opr_name + "ProcessAction.action?" + str,
> success: function(data)
> {
> if(data==1)
> {
> return_yn = true;
> }
> else
> {
> $("#action_error_div").html(data);
> $("#action_error_div").removeClass().addClass("errormsg");
> return_yn = false;
> }
> }
> });
> return return_yn;
> }
> </script>
>
> ProcessAction.java
> =======================
> public String check_search_opr() throws Exception
> {
> inputStream = new ByteArrayInputStream("".getBytes());
> PrintWriter out = res.getWriter();
> res.setContentType("text/html");
> StringBuffer sb = new StringBuffer();
> .... if existing error sb.append....
> String str = sb.toString();
> if(!Utils.isNullOrBlank(str))
> {
> out.println(str);
> }
> else
> {
> out.println(1);
> }
> out.flush();
> return "ajax_forward";
> }
>
> struts.xml
> ===============
> <action name="*ProcessAction" method="{1}" class="ProcessAction">
> <result name="success" type="tiles">...</result>
> <result name="error" type="tiles">...</result>
> <result name="ajax_forward" type="stream">
> <param name="contentType">text/html</param>
> <param name="inputName">inputStream</param>
> </result>
> </action>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

Re: SEVERE: Servlet.service() for servlet default threw exception, java.lang.IllegalStateException

Posted by Emi Lu <em...@encs.concordia.ca>.
On 07/27/2011 01:55 AM, Łukasz Lenart wrote:
> 2011/7/26 Emi Lu<em...@encs.concordia.ca>:
>>> Did you try to call check_search_oprProcessAction.action directly ?
>>> And maybe it's better to JSON plugin instead of home made protocol ?
>
> I was thinking about JSON result plus jQuery.

For people have similar questions, my solution for now based on ajax + 
jQuery is:
=========================================================================
(1) In global tile template.jsp, added
    <div id="ajax_error_div" align="left">

    </div>


(2) In script.js, defined:
==============================
function ajax_check(url)
{
    var xmlhttp;
    var str = $("form").serialize(); //http://api.jquery.com/serialize/
    var tmp_str = "";
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
       xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
       xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
       if (xmlhttp.readyState==4 && xmlhttp.status==200)
       {
          document.getElementById("ajax_error_div").innerHTML = 
xmlhttp.responseText;
       }
    }
    xmlhttp.open("POST", url, false);
 
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); 

    xmlhttp.send(str);
    var str = document.getElementById("ajax_error_div").innerHTML;
    if(str == null || str.trim() == "")
    {
       return true;
    }
    return false;
}


(3) main_display.jsp
=======================
<s:submit value="Search"
           theme="simple"
           onclick="return ajax_check('ajax_checkProcessAction')"
           action="searchProcessAction" />

(4) struts.xml
=================
     <action name="*ProcessAction"  method="{1}" class="ProcessAction">
       <result name="success" type="tiles">browse_main_page</result>
       <result name="error"   type="tiles">browse_main_page</result>
       <result name="ajax_check" >
	    /WEB-INF/pages/errorinfo/ajax_error_check.jsp
      </result>
    </action>


(5) ajax_error_check.jsp
==========================
<%@ taglib prefix="s"     uri="/struts-tags"                       %>
    <s:if test="hasActionMessages()">
       <center>
       <div id="action_message_div"
            style="width: 700px; border:thin solid black; 
background-color:#C5D1C0; padding-left: 10px; margin-bottom: 5px; "
            align="left">
		   <s:iterator value="actionMessages">
	      <li>
	         <B><s:property escape="false" /> </B>
	      </li>
		   </s:iterator>
       </div>
       </center>
    </s:if>


    <s:if test="hasActionErrors()">
      <center>
       <div align="left" style="width: 700px; border:thin solid black; 
background-color:#D0CCAE; padding-left: 10px; margin-bottom: 5px">
          <s:iterator value="actionErrors">
          <li>
             <B><s:property escape="false" /> </B>
          </li>
          </s:iterator>
       </div>
       </center>
    </s:if>


Thank you for all inputs!

Emi

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: SEVERE: Servlet.service() for servlet default threw exception, java.lang.IllegalStateException

Posted by Łukasz Lenart <lu...@googlemail.com>.
2011/7/26 Emi Lu <em...@encs.concordia.ca>:
>> Did you try to call check_search_oprProcessAction.action directly ?
>> And maybe it's better to JSON plugin instead of home made protocol ?

I was thinking about JSON result plus jQuery.


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
Warszawa JUG conference - Confitura http://confitura.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: SEVERE: Servlet.service() for servlet default threw exception, java.lang.IllegalStateException

Posted by Emi Lu <em...@encs.concordia.ca>.
Hello,

> W dniu 26 lipca 2011 16:13 użytkownik Emi Lu<em...@encs.concordia.ca>  napisał:
>> It seems that I found the problem. When I commented out ajax section
>> "onclick="return ajax_check_search_table('check_search_opr')"", the error is
>> gone. But I need ajax check support.
>
> Did you try to call check_search_oprProcessAction.action directly ?
> And maybe it's better to JSON plugin instead of home made protocol ?

Situation is:
=====================
(1) a.jsp
  part1 -> search form
  part2 => huge calculation in ActionClass.java;
           results are shown by using displaytag


(2) Checks are needed in part1, but I need avoid calculation in part2.

    Moreover, a.jsp only part1 will be reloaded, but not the whole page.

    part1@a.jsp calls method1 in ActionClass.java


(3) JSON/jquery sj:submit seems does not support "action" parameter, it 
could not dispatch to another method, isn't ?

<sj:submit targets="result"
   button="true"
   validate="true"
   validateFunction="customeValidation"
   onBeforeTopics="removeErrors"
   onSuccessTopics="removeErrors"
   value="Submit"
   indicator="indicator"
   action="method1ProcessActionClass" //does not dispatch! while 
s:submit works
/>



Could you suggest a good way?
====================================
(1) Do not reload whole jsp
(2) Calculation must be done through ActionClass.java (extends 
ActionSupport)
    The calculation is through database queries, so have to be done 
through action class.

    According to the check results, display error message to users 
through part1@a.jsp

  Only if no error return, part2 will be calculated and reloaded.

Thanks alot!
Emi





---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: SEVERE: Servlet.service() for servlet default threw exception, java.lang.IllegalStateException

Posted by Łukasz Lenart <lu...@googlemail.com>.
W dniu 26 lipca 2011 16:13 użytkownik Emi Lu <em...@encs.concordia.ca> napisał:
> It seems that I found the problem. When I commented out ajax section
> "onclick="return ajax_check_search_table('check_search_opr')"", the error is
> gone. But I need ajax check support.

Did you try to call check_search_oprProcessAction.action directly ?

And maybe it's better to JSON plugin instead of home made protocol ?


Kind regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
Warszawa JUG conference - Confitura http://confitura.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: SEVERE: Servlet.service() for servlet default threw exception, java.lang.IllegalStateException

Posted by Emi Lu <em...@encs.concordia.ca>.
Hi Łukasz,

>> tomcat6 + struts2.2.3 + tiles2.2.2 + springframework3.05 + displaytag 1.2.
>
> Could you list the jars in WEB-INF/lib ? It looks like you're mixing
> different version of jars.

It seems that I found the problem. When I commented out ajax section 
"onclick="return ajax_check_search_table('check_search_opr')"", the 
error is gone. But I need ajax check support.

Do you know why ajax and which parts in ajax cause this exception?

Thanks a alot!
Emi

----

form.jsp
===========
....
<s:submit value="Login" onclick="return 
ajax_check_search_table('check_search_opr')" action="method1ActionView" />
  .....
<script type="text/javascript">
function  ajax_check_search_table(opr_name)
{
var str = $("form").serialize(); //http://api.jquery.com/serialize/
var return_yn = false;
	
$.ajax({	
   async: false,
   url : opr_name + "ProcessAction.action?" + str,
   success: function(data)
   {
    if(data==1)
    {
      return_yn = true;
    }
    else
    {
       $("#action_error_div").html(data);
       $("#action_error_div").removeClass().addClass("errormsg");
       return_yn = false;
    }
  }
});
    return return_yn;
}
</script>

ProcessAction.java
=======================
  public String check_search_opr() throws Exception
{
  inputStream              = new ByteArrayInputStream("".getBytes());
  PrintWriter out          = res.getWriter();
  res.setContentType("text/html");
  StringBuffer sb = new StringBuffer();
   .... if existing error sb.append....
       String str = sb.toString();
       if(!Utils.isNullOrBlank(str))
       {
          out.println(str);
       }
       else
       {
          out.println(1);
       }
       out.flush();
       return "ajax_forward";
    }

struts.xml
===============
<action name="*ProcessAction"  method="{1}" class="ProcessAction">
    <result name="success" type="tiles">...</result>
    <result name="error"   type="tiles">...</result>
    <result name="ajax_forward" type="stream">
       <param name="contentType">text/html</param>
       <param name="inputName">inputStream</param>
    </result>
</action>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: SEVERE: Servlet.service() for servlet default threw exception, java.lang.IllegalStateException

Posted by Łukasz Lenart <lu...@googlemail.com>.
W dniu 26 lipca 2011 15:11 użytkownik Emi Lu <em...@encs.concordia.ca> napisał:
> tomcat6 + struts2.2.3 + tiles2.2.2 + springframework3.05 + displaytag 1.2.

Could you list the jars in WEB-INF/lib ? It looks like you're mixing
different version of jars.


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
Warszawa JUG conference - Confitura http://confitura.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: SEVERE: Servlet.service() for servlet default threw exception, java.lang.IllegalStateException

Posted by Emi Lu <em...@encs.concordia.ca>.
>>   <filter-mapping>
>>       <filter-name>struts</filter-name>
>>       <url-pattern>/*</url-pattern>
>>       <dispatcher>REQUEST</dispatcher>
>>       <dispatcher>INCLUDE</dispatcher>
>>    </filter-mapping>
>
> Did you try to remove these dispatcher params ? Or add FORWARD ?

I tried as well, but still got the following exceptions. The server did 
not die and it seems work fine. But each action returns such SEVERE 
exception. Why???

tomcat6 + struts2.2.3 + tiles2.2.2 + springframework3.05 + displaytag 1.2.

I do need help what may cause this exception. From the outputs, I cannot 
see any hint!

-------------------------------
SEVERE: Servlet.service() for servlet default threw exception
java.lang.IllegalStateException
at 
org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:407)
at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:819)
at 
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:519)
at 
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at 
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at 
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
-------------------------------
Thanks a lot!
Emi

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org