首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> Java 程式設計 >> Java 相關知識

Struts2 redirectAction 重導向異常:URL 中莫名出現 "pass" 參數的排查與解決

     編輯:Java 相關知識

專案中使用 <result type="redirectAction">my.action</result> 進行 Action 轉發,預期 URL 為 https://localhost:8080/focus/account/my.action,實際卻跳轉至 https://localhost:8080/focus/pass/account/my.action 導致 404。多方排查後定位為 Spring 整合 JCR170 時的 Bean 定義干擾。

問題現場

<result name="success" type="redirectAction">my.action</result>

正常:/focus/account/my.action
異常:/focus/pass/account/my.action

根因定位:Spring Bean 定義污染

Spring 配置中為 JCR170 定義密碼 Bean:

<bean id="password" class="java.lang.String">
 <constructor-arg index="0" value="pass"/>
</bean>

<bean id="jcrSessionFactory" class="org.springmodules.jcr.JcrSessionFactory">
 <property name="credentials">
 <bean class="javax.jcr.SimpleCredentials">
 <constructor-arg index="0" value="bogus"/>
 <constructor-arg index="1">
 <bean factory-bean="password" factory-method="toCharArray"/>
 </constructor-arg>
 </bean>
 </property>
</bean>

關鍵點:Bean id 為 password,值為 "pass"。此字串以不明機制滲入 Struts2 的 redirectAction URL 構建過程,導致路徑中多出 /pass/ 片段。

解決方案:消除具名 Bean 依賴

將密碼 Bean 內聯為直接值,移除 factory-bean 引用:

<!-- 註釋或刪除 password Bean -->
<!-- <bean id="password" class="java.lang.String"> ... </bean> -->

<bean id="jcrSessionFactory" class="org.springmodules.jcr.JcrSessionFactory">
 <property name="credentials">
 <bean class="javax.jcr.SimpleCredentials">
 <constructor-arg index="0" value="bogus"/>
 <constructor-arg index="1" value="pass"/> <!-- 直接內聯字串,Spring 自動轉 char[] -->
 </bean>
 </property>
</bean>

修改後重新部署,重導向 URL 恢復正常,/pass/ 片段消失。

後記

具體滲入機制尚不明確(推測與 Struts2 的參數解析或 Spring 的 Bean 名稱註冊機制有關),但「移除同名具名 Bean、改用內聯值」可有效規避。若有讀者知曉深層原理,歡迎補充。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved