經常使用的幾種Result組件 1)JSP響應 dispatcher :採用請求轉發方式調用JSP組件響應。 redirect:採用請求重定向方式調用JSP組件響應。(在重定向後,原request和action都被銷燬掉,所以在JSP獲取不到值) 使用格式以下: <result type="dispatcher"> <param name="location">/msg.jsp</param> </result> 或者使用簡寫 <result type="dispatcher"> /msg.jsp </result> 2)Action響應 delete.action?id=1---->DeleteAction--->ListAction--->list.jsp redirectAction:採用重定向方式發出一個*.action請求 chain:採用轉發方式發出一個*.action請求 使用格式以下: 調用不一樣命名空間的action時: <result type="redirectAction"> <param name="actionName">請求名</param> <param name="namespace">命名空間</param> </result> 調用相同命名空間的action時: <result type="redirectAction"> 請求名 </result> -->*.action--->Action1--chain-->Action2---chain-->Action3 3)流響應 典型功能:驗證碼和下載。 stream:能夠將Action中的一個InputStream類型屬性以流方式響應輸出。 使用格式以下: <result type="stream"> <param name="inputName">Action屬性</param> </result> 4)JSON響應 負責對Ajax請求進行數據響應。 json:能夠將Action中的一個屬性或多個屬性以json格式響應輸出 使用格式以下: 若是須要返回一個屬性值 <result type="json"> <param name="root">Action屬性</param> </result> 若是須要返回多個屬性值 <result type="json"> <param name="includeProperties"> Action屬性1,Action屬性2 </param> </result> 若是須要返回全部屬性值 <result type="json"></result> 注意:使用前須要引入struts-json-plugin.jar,而後將<package>元素的extends設置成"json-default"