FileDocCategorySizeDatePackage
Token.javaAPI DocExample4083Mon Jul 23 13:26:36 BST 2007org.apache.struts2.components

Token

public class Token extends UIBean
Stop double-submission of forms.

The token tag is used to help with the "double click" submission problem. It is needed if you are using the TokenInterceptor or the TokenSessionInterceptor. The s:token tag merely places a hidden element that contains the unique token.

Examples


<s:token />

see
org.apache.struts2.interceptor.TokenInterceptor
see
org.apache.struts2.interceptor.TokenSessionStoreInterceptor

Fields Summary
public static final String
TEMPLATE
Constructors Summary
public Token(com.opensymphony.xwork2.util.ValueStack stack, HttpServletRequest request, HttpServletResponse response)


           
        super(stack, request, response);
    
Methods Summary
private java.lang.StringbuildToken(java.lang.String name)

        Map context = stack.getContext();
        Object myToken = context.get(name);

        if (myToken == null) {
            myToken = TokenHelper.setToken(name);
            context.put(name, myToken);
        }

        return myToken.toString();
    
protected voidevaluateExtraParams()
First looks for the token in the PageContext using the supplied name (or {@link org.apache.struts2.util.TokenHelper#DEFAULT_TOKEN_NAME} if no name is provided) so that the same token can be re-used for the scope of a request for the same name. If the token is not in the PageContext, a new Token is created and set into the Session and the PageContext with the name.

        super.evaluateExtraParams();

        String tokenName;
        Map parameters = getParameters();

        if (parameters.containsKey("name")) {
            tokenName = (String) parameters.get("name");
        } else {
            if (name == null) {
                tokenName = TokenHelper.DEFAULT_TOKEN_NAME;
            } else {
                tokenName = findString(name);

                if (tokenName == null) {
                    tokenName = name;
                }
            }

            addParameter("name", tokenName);
        }

        String token = buildToken(tokenName);
        addParameter("token", token);
        addParameter("tokenNameField", TokenHelper.TOKEN_NAME_FIELD);
    
protected java.lang.StringgetDefaultTemplate()

        return TEMPLATE;
    
public java.lang.StringgetTokenNameField()
This will be removed in a future version of Struts.

deprecated
Templates should use $parameters from now on, not $tag.

        return TokenHelper.TOKEN_NAME_FIELD;