开发者

How to get the parameter n its values from action to JSP in Struts2

I have action like below in struts.xml

defaultPage defaultPage

I want to redirect control to same page along with few parameters depending on the result from the method "sentMailToContactUs"

Ex:

if sentMailToContactUs return success/Fail

<result name="success" type="redirctAction">
<param name ="actionName">Contact</param>
<param name ="resultRtn">Y</param>
</result>

    <result name="fail" type="redirctAction">
<param name ="actionNam开发者_JAVA技巧e">Contact</param>
<param name ="resultRtn">N</param>
</result>

How to read the above parameter from action in JSP...........?

If parameter resultRtn = 'Y' --> Some controls are available

If parameter resultRtn = 'Y' --> Some controls are not available,

If parameter resultRtn = 'null' --> Show all Controls

Thank you......


For me it worked something like this..

In struts.xml:

<result name="success" type="redirectAction">
     <param name="actionName">Contact</param>
     <param name="resultVariable">${resultVariable}</param>
</result>

In action Class getter Setter for resultVariable

In Contact page to receive parameter n its value:

<s:set var="reaultTyp"><s:property value="%{#parameters['resultVariable']}"/></s:set>

thank you both....


You need to have a set method for resultRtn in your Contact action to set the 'Y', 'N' or other values. And you need to have a get method for your JSP to call so that you can retrieve the value and display the controls accordingly.


The param tag is not for setting parameters on the URL, its for setting configuration parameters for the result. You should be able to set the query string parameters within the actionName as follows:

<result name="success" type="redirctAction">
    <param name="actionName">Contact?resultRtn=Y</param>
</result>

<result name="fail" type="redirctAction">
    <param name="actionName">Contact?resultRtn=N</param>
</result>

You can also use a normal redirect in place of a redirectAction here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜