遊客:  註冊 | 登錄 | 幫助





標題: [討論] Jakarta Struts Action Forward
mickeyGoUp     Rank: 7Rank: 7Rank: 7
版主
性別 男
UID 5

精華 0
帖子 35511
積分 5235   詳情

閱讀權限 150
註冊 2006-3-24
來自 美國滴滴尼
狀態 離線

 
 
 
 
發表於 2006-8-3 12:46 AM  資料  個人空間  短訊  加為好友 
Jakarta Struts Action Forward

雖然 Struts 已經出左好耐﹐但我都係最近先開始用。

今日發現有 d 奇怪... 係唔係一定係咁架呢?

我有 Action 1 (Form 1) -> JSP 1﹐同 Action 2 (Form 2) -> JSP 2﹐而 Form 1 就有 field1 and field2﹐Form 2 就有 field3 and field4。

咁在 JSP 1 內就順理成張用 struts 既 tag libraries 啦:

<html:form action="action1">
    <html:hidden property="field1"/>
    <html:hidden property="field2"/>
    <html:submit>Go</html:submit>
</html:form>

咁每次禁 Go 就去 Action 1 走一轉啦﹐ok 啦...  

好勒﹐如果某 d 情況下﹐我想佢由 JSP 1 submit 去 Action 2﹐咁我緊係試下將 JSP 1 改成:

<html:form action="action2">
    <html:hidden property="field3"/>
    <html:hidden property="field4"/>
    <html:submit>Go</html:submit>
</html:form>

點知一去 Action 1﹐佢轉到 JSP 1 後﹐就話搵唔到 Form 2!  無錯勒﹐Action 2 係 map 去 Form 2 架嘛﹐而 Action 1 forward 去 JSP 1 時﹐根本無 setup 到 Form 2﹐咁緊係唔得啦!

咁我點先可以做到我以上既動作呢????

最後我要將 field3 field4 加入 Form 1﹐在將 JSP 1 改用:

<html:form action="action1">
    <html:hidden property="field1"/>
    <html:hidden property="field2"/>
    <html:hidden property="field3"/>
    <html:hidden property="field4"/>
    <input type=hidden name=goAction2 value=yes />
    <html:submit>Go</html:submit>
</html:form>

即係佢會 submit 返去 Action 1﹐當 Action 1 見到 goAction2 係 "yes" 時﹐就唔好 forward 去 JSP 1﹐而係 forward 去 Action 2。

咁究竟係唔係正確既做法呢??  唔知...........................  -__-

頂部

  nicky_39     Rank: 2Rank: 2
藍之初
性別 保密
UID 8192

精華 0
帖子 14
積分 100   詳情

閱讀權限 30
註冊 2006-8-21
來自
狀態 離線

 
 
 
 
發表於 2006-8-24 06:03 PM  資料  個人空間  短訊  加為好友 
回覆 #1 mickeyGoUp 的帖子

What have you got set up in the struts-config.html?  

For example, in the within the <action-mappings> scope, if you have set:
<action path="/action1" type="action1Action" name="form1" scope="request" input="form1.jsp">               
    <forward name="action1" path="form1.jsp"/>                       
</action>

This would be couple form1 and action1.

Try playing around with the struts-config.html.

Hope this has helped.

頂部



mickeyGoUp     Rank: 7Rank: 7Rank: 7
版主
性別 男
UID 5

精華 0
帖子 35511
積分 5235   詳情

閱讀權限 150
註冊 2006-3-24
來自 美國滴滴尼
狀態 離線

 
 
 
 
發表於 2006-8-24 07:44 PM  資料  個人空間  短訊  加為好友 


QUOTE:
原帖由 nicky_39 於 2006-8-24 06:03 AM 發表
What have you got set up in the struts-config.html?  

For example, in the within the <action-mappings> scope, if you have set:
<action path="/action1" type="action1Action" name="form1" scope="request" input="form1.jsp">               
    <forward name="action1" path="form1.jsp"/>                        
</action>

This would be couple form1 and action1.

Try playing around with the struts-config.html.

Hope this has helped.

Thanks for your suggestions!  Inthe struts-config.xml file, I have:

<action path="/action1" type="action1Action" name="form1" scope="request" input="form1.jsp">               
    <forward name="action1" path="form1.jsp"/>                        
</action>
<action path="/action2" type="action2Action" name="form2" scope="request" input="form2.jsp">               
    <forward name="action1" path="form2.jsp"/>                        
</action>

The forwarding itself works ok.  It goes to where I want it to.  The problem occured when I want to submit form1.jsp to action2, if the form tag points to action2, all the tag library tags must be in form2 bean.  But after action1 forwarded to form1.jsp, which contains a form with action2, it complains (see my first post for more details).  So form1.jsp must contains form with action1.  That means I cannot submit form1.jsp directly to action2, I have to submit it back to action1, and let action1 do the forwarding to action2.

At the end, it works what I wanted it to, but I am just not sure if this is the proper way and the only way to do this.  

What do you think?

頂部

快速美言
           


當前時區 GMT+8, 現在時間是 2024-11-27 07:14 AM

    Powered by Discuz!  © 2001-2007 Comsenz Inc.   
Processed in 0.011837 second(s), 9 queries

清除 Cookies - 聯繫我們 - LIPS Corner 新天藍 - Archiver