又发现struts2 rest plugin的一个问题

又发现rest plugin的一个问题:

DefaultContentTypeHandlerManager:
// Don't return any content for PUT, DELETE, and POST where there are no errors
if (!statusNotOk && !"get".equalsIgnoreCase(req.getMethod())) {
target = null;
}
导致经过正确处理的put和delete请求,无法返回xml/json内容(成功提示等)
间接导致jquery ajax 调用失败(response=null)?

如果可能,如何重写该类(只需将这段屏蔽掉即可)?
http://mail-archives.apache.org/mod_mbox/struts-user/201002.mbox/%3C3d5bf9841002231520u56375851rd0a0ac4f80b6c7b3@mail.gmail.com%3E
http://mail-archives.apache.org/mod_mbox/struts-user/201002.mbox/thread?2
但这个mail仍然没有人回答。。


/
竟然也有人在这篇文章的末尾弱弱的提问这个问题:
http://raibledesigns.com/rd/entry/go_light_with_apache_struts

终于发现这个问题的确是个bug,在apache的bug列表里面有:
http://issues.apache.org/jira/browse/WW-3303

/
项目比较着急,没时间继续找办法了。直接修改struts2-rest-plugin 的源代码解决之。
好在只是修改一个插件的代码,并且strut2全部使用maven作为构建工具,直接在源代码中屏蔽掉这段话,然后在rest的根目录mvn clean install,我的程序便能成功运行了,其实这么做也不赖,呵呵。。。

但这样做的前提是我得把所作的修改记下来,不然升级strut2的时候又坏了,除非这个问题在下一个版本中已经更正。还是在这里先提醒一下自己。。。
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果您想在 Struts2 项目中将 javax 包替换为 jakartaee 包,可以按照以下步骤进行操作: 1. 在 pom.xml 文件中,将 struts2-core 的版本号修改为 2.5.26 或更高版本,以支持 jakartaee 包。同时,将 struts2-convention-pluginstruts2-junit-plugin 的版本号也修改为相应的版本: ``` <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-core</artifactId> <version>2.5.26</version> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-convention-plugin</artifactId> <version>2.5.26</version> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-junit-plugin</artifactId> <version>2.5.26</version> <scope>test</scope> </dependency> ``` 2. 在 pom.xml 文件中,排除 javax 包的依赖,添加 jakartaee 包的依赖,例如: ``` <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency> ``` 修改为: ``` <dependency> <groupId>jakarta.servlet</groupId> <artifactId>jakarta.servlet-api</artifactId> <version>4.0.4</version> <scope>provided</scope> <exclusions> <exclusion> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </exclusion> </exclusions> </dependency> ``` 3. 在 pom.xml 文件中,使用 Maven 依赖插件(maven-dependency-plugin)将本地仓库中的 javax 包替换为 jakartaee 包: ``` <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>3.1.2</version> <executions> <execution> <id>replace-javax-with-jakarta</id> <phase>process-resources</phase> <goals> <goal>copy</goal> </goals> <configuration> <artifactItems> <artifactItem> <groupId>org.glassfish.jakartaee</groupId> <artifactId>jakartaee-api</artifactId> <version>8.0.0</version> <type>jar</type> <overWrite>true</overWrite> <outputDirectory>${project.build.directory}/classes</outputDirectory> <includes>javax/**</includes> </artifactItem> </artifactItems> </configuration> </execution> </executions> </plugin> </plugins> </build> ``` 这样,就可以将 Struts2 项目中的 javax 包替换为 jakartaee 包。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值