2008年5月5日 星期一

Struts-DispatchAction使用

如果A網頁進入Action時可能會有三個動作:新增資料、刪除資料或到查詢頁,
在進入一般的Action(org.apache.struts.action.Action)中會進入execute方法,
然後寫一些if-else去判斷如何執行這三個動作...在程式的可讀性很差。
而使用DispatchAction後,就可以自行定義三個方法當做進入點,而不必再使用execute,

設定方式如下:
1.在Struts-Config.xml中設定action tag的parameter="method"





2. 在jsp中設定一個hidden參數為"method"對應上一步的設定,並設定goSearchPage方法準備讓網頁移動到查詢頁,

3.讓Action繼承DispatchAction並設定goSearchPage方法,對應JSP中的form.method.value
public class CSDP01 extends DispatchAction {
/**
* 移動至查詢頁
*/
public ActionForward goSearchPage(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception
{ return (mapping.findForward("search"));
}
}









2008年4月28日 星期一

Struts web.xml 中文編碼設定

今天在寫程式時,用Eclipse + Tomcat5.5測試,

哇咧~中文怎麼進資料庫變亂碼,JSP沒問題有編成UTF-8,Bean也不會有問題,

那就是Server設定的問題 ,修正之後就OK了: