SoFunction
Updated on 2025-03-01

Struts json type exception returns to js pop-up box problem solution

Struts json type exception returns to js pop-up box problem solution

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/</result> 
      <result name="over">/js/</result> 
    </global-results> 
     
    <global-exception-mappings> 
      <exception-mapping result="error" exception="" /> 
      <exception-mapping result="over" exception="" /> 
    </global-exception-mappings> 
    <action name="ConnONGL_*" class="" method="{1}"> 
      <result name="success" type="json" > 
          <param name="root">jsonMap</param> 
      </result> 
  </action>  

When an action throws an exception, the ideal situation is to go to the exception information page or the js pop-up prompt. Since it is a json type, the exception information page or pop-up prompt can only be displayed in the browser console

Modify ajax request and comment out the dataType: "Json" and the js pop-up box can be displayed normally.

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

Thank you for reading, I hope it can help you. Thank you for your support for this site!