ERROR ParametersInterceptor:34 - Developer Notification ... Unexpected Exception caught setting 'police.id' on 'class ...PoliceUpdateAction: Error setting expression 'police.id' with value '[Ljava.lang.String;@7a0adf91'
ERROR Dispatcher:38 - Could not find action or result /pservermy/police_update
No result defined for action ...PoliceUpdateAction and result input
<s:textfield name="police.id" />,Struts2 嘗試將請求參數(字符串數組 String[])設置到 Action 的 police.id(類型 Long)。OGNL 類型轉換器無法將數組直接轉為 Long,拋出異常;ActionContext,並尝試返回 input 結果以便頁面顯示錯誤;input 結果:struts.xml 中該 Action 未定義 <result name="input">,導致 Dispatcher 拋出 No result defined for action ... and result input,掩蓋了真實的轉換錯誤。若 police 是 Action 中的對象屬性(含 id 字段),表單應綁定對象圖導航:
<s:textfield name="police.id" value="%{police.id}" />
確保 Action 有 getPolice() 返回非空對象,或在 prepare() 中初始化。OGNL 會自動實例化 police 並設置 id。
在 Action 中添加 private Long policeId; 及 getter/setter,表單用 name="policeId"。避免對象圖導航複雜性。
input 結果並展示錯誤<action name="police_update" class="..." method="update">
<result name="success" type="redirect-action">...</result>
<result name="input">/police/edit.jsp</result> <!-- 必須添加 -->
</action>
在 edit.jsp 使用 <s:fielderror /> 顯示轉換錯誤信息,便於調試。
實現 TypeConverter 處理 String[] → Long,在 xwork-conversion.properties 或註解註冊。
struts.devMode=true(已開啟),查看控制台完整堆疊;input 結果觀察具體字段錯誤;System.out.println(Arrays.toString(request.getParameterValues("police.id")));。表單字段與 Action 屬性類型不匹配 → OGNL 轉換失敗 → ParametersInterceptor 拋異常 → 尋找 input 結果失敗 → 404 錯誤掩蓋真因。修正字段綁定或補全 input 結果即可斷鏈解決。