0

My website use struts and tiles. I use this link to link to register form:

<a href='<s:url action="register" namespace="/vtv"  />' >Register</a>

here is the register.jsp:

<s:form namespace="/vtv" action="register">
        <s:textfield label="Username" name="username" />
        <s:textfield label="Password" name="password" />
</s:form>

In action, i insert the user :

public String execute() {
    String retVal = ERROR;
    try {
            MemberDAO.InsertUser(mo);
            retVal = SUCCESS;
        }
    } catch (Exception e) {
        retVal = ERROR;
    }
    return retVal;
}

in tiles file, i define:

<definition name="vtv.register" extends="basic">
    <put-attribute name="content" value="/modules/register/register.jsp" />
</definition>

and in struts file:

    <package name="Register" namespace="/vtv" extends="struts-default">
    <result-types>
        <result-type name="tiles"
                     class="org.apache.struts2.views.tiles.TilesResult" />
    </result-types>
    <action name="register" class="vtv.action.RegisterAction">
        <result name="success" type="tiles">vtv.register</result>
        <result name="error" type="tiles">vtv.error</result>
    </action>
</package>

My problem is how can i redirect to register page using link

<a href='<s:url action="register" namespace="/vtv"  />' >Register</a>

without doing the execute in action ? How can i know if this is redirect or submit ?

Roman C
  • 49,761
  • 33
  • 66
  • 176
hieu
  • 56
  • 2
  • 6

1 Answers1

0

In your <s:url> tag you can specify a specific method you want to invoke in your RegisterAction:

<s:url action="register" method="yourRedirectMethodName" namespace="/vtv"  />

And then in your action define:

public String yourRedirectMethodName() {
    // Redirect logic
    return SUCCESS;
}

That way form submits will invoke execute() whereas the above link will invoke yourRedirectMethodName().

Pat
  • 25,237
  • 6
  • 71
  • 68
  • is there IsPostBack variable like Asp.net in struts ? – hieu Jul 22 '10 at 06:51
  • Not that I know of but something else that occurred to me is that you could check if your Action's form properties were set. If yes, it's a form submit. If no, it's a redirect from a link. – Pat Jul 22 '10 at 10:44