终于把 Ext.Direct 这块硬骨头啃下来了,说实话在加载和提交过程中踩了不少坑。基础扎实确实能帮大忙,排错时体会尤其明显。下面整理三个典型的 Ext.Direct 加载与提交错误,包括 ArrayIndexOutOfBoundsException、Controlled server error 以及 ClassNotFoundException,希望能帮到正在折腾的朋友。
错误一:启动时抛出 ArrayIndexOutOfBoundsException
严重: StandardWrapper.Throwable
ja va.lang.ArrayIndexOutOfBoundsException: 1
at com.softwarementors.extjs.djn.api.RegisteredStandardMethod.isValidFormHandlingMethod(RegisteredStandardMethod.ja va:53)
at com.softwarementors.extjs.djn.scanner.Scanner.scanAndRegisterActionClass(Scanner.ja va:206)
...
这个异常通常指向一个常见问题:注解使用不当。排查后发现元凶是 @DirectFormPostMethod 注解。将其替换为 @DirectMethod,同时删除由 @DirectFormPostMethod 生成的 import 语句——import com.softwarementors.extjs.djn.config.annotations.DirectFormPostMethod;,问题即可解决。
错误二:运行时报 "Controlled server error"
ERROR: com.softwarementors.extjs.djn.router.processor.standard.json.JsonRequestProcessor - "(Controlled) server error: 1 for Method 'FormAction.submitData'" (rid=1000)
ja va.lang.ArrayIndexOutOfBoundsException: 1
at com.softwarementors.extjs.djn.router.processor.standard.json.JsonRequestProcessor.checkJsonMethodParameterTypes(JsonRequestProcessor.ja va:352)
...
这次是控制层出错,说明逻辑层面有问题。放心,这并非 xml 配置问题,而是传入的参数不匹配。重点在于参数传递的语法细节。排查后发现,Java 接口要求传入两个参数——public Info submitData(String name,String password),但 ExtJS 端实际传入的参数被拼接成一个字符串:var params= username.getValue()+Password.getValue(); FormAction.submitData(params,function(result,e){}。修改并不复杂,只需将参数分开传递:FormAction.submitData(username.getValue(),Password.getValue(),function(result,e){}。
错误三:Servlet 启动时报 ClassNotFoundException
FATAL: com.softwarementors.extjs.djn.servlet.DirectJNgineServlet - "Unable to find class 'com.softwarementors.extjs.djn.test.config.GsonBuilderConfiguratorForTesting'"
com.softwarementors.extjs.djn.servlet.ServletConfigurationException: Unable to find class 'com.softwarementors.extjs.djn.test.config.GsonBuilderConfiguratorForTesting'
...
原因非常直接——那个类根本不存在。该配置在 web.xml 中被引用,如果只是在测试环境下使用且实际不需要,直接删除相关配置即可:
registryConfiguratorClass
com.softwarementors.extjs.djn.test.servlet.config.RegistryConfiguratorForTesting
gsonBuilderConfiguratorClass
com.softwarementors.extjs.djn.test.config.GsonBuilderConfiguratorForTesting
以上三个坑基本囊括了 Ext.Direct 加载与提交过程中的常见问题,对照排查即可快速解决。

