You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

从Struts 2.5升级至Struts 6.3.0.2后Ajax调用失效,求助sj:div问题

Struts 6.3.0.2升级后sj:div Ajax调用故障排查方案

1. 优先解决插件版本兼容性问题

Struts 6.x基于Jakarta EE 9+规范,旧版适配Struts 2.5的struts2-jquery-plugin依赖Java EE API,两者不兼容,必须替换为适配Struts 6的插件版本:

<dependency>
    <groupId>com.jgeppert.struts2.jquery</groupId>
    <artifactId>struts2-jquery-plugin</artifactId>
    <!-- 需使用4.0.0及以上版本,示例为最新稳定版 -->
    <version>4.0.3</version>
</dependency>

2. 调整sj:div标签属性适配新版本

Struts jQuery 4.x对部分标签属性做了更名或逻辑调整,针对你的代码修改如下:

  • 将listenTopics替换为新版支持的subscribeTopics
  • 将formIds替换为更简洁的form属性(直接传入表单选择器)

修改后的标签代码:

<sj:div cssStyle="text-align:center" 
        id="test" 
        href="%{desUrl}" 
        form="#getActionForm" 
        loadingText="Loading..." 
        indicator="indicator" 
        subscribeTopics="/refresh" 
        escapeHtmlBody="true">
</sj:div>

3. 排查前端JS加载冲突

  • 移除页面中手动引入的jQuery,让插件自动加载适配版本,避免版本冲突
  • 打开浏览器控制台,检查是否存在$ is not defined、方法不存在等JS报错,根据报错调整加载逻辑

4. 验证Action响应有效性

直接在浏览器访问%{desUrl}对应的地址,确认test_actionMethod能返回正常的HTML/JSON内容,且无服务器端异常抛出

5. 检查Struts配置项

确保struts.xml中启用jQuery插件:

<constant name="struts.jquery.enabled" value="true" />

内容的提问来源于stack exchange,提问作者Kiran

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 09:04:57