Solution of struts json type abnormal return to js bullet frame problem

  • 2021-12-11 18:39:54
  • OfStack

Solution of struts json type abnormal return to js bullet frame problem

When the struts framework is configured with exceptions, for example:


<package name="sysCnn" namespace="/" extends="json-default"> 
    <global-results> 
      <result name="error">/WEB-INF/pages/error.jsp</result> 
      <result name="over">/js/over.js</result> 
    </global-results> 
     
    <global-exception-mappings> 
      <exception-mapping result="error" exception="java.lang.Exception" /> 
      <exception-mapping result="over" exception="com.xxx.exception.OverException" /> 
    </global-exception-mappings> 
    <action name="ConnONGL_*" class="com.xxx.action.LoginAction" method="{1}"> 
      <result name="success" type="json" > 
          <param name="root">jsonMap</param> 
      </result> 
  </action>  

When action throws an exception, ideally, you want to go to the exception information page or js pop-up box prompt. Because of json type, the exception information page or pop-up box prompt can only be displayed in console of the browser

To modify ajax, comment out dataType: "Json", and the js bullet box can be displayed normally


$.ajax({ 
    url:$.contextPath+"/ConnONGL_login", 
    //dataType:"Json",   This line is commented out  
    async:false, 
    cache:false, 
    data:{ 

Thank you for reading, hope to help everyone, thank you for your support to this site!


Related articles: