Struts2.2.1 token tag example.
Posted on: January 17, 2011 at 12:00 AM
In this example, you will see the use of struts token tag.

Struts2.2.1 token tag example.

In this example, you will see the use of taken tag of struts2.2.1. It helps double click problem. The s:token tag merely places a hidden element that contains the unique token.

 1- index.jsp

<%@ taglib uri="/struts-tags" prefix="s" %>




<s:form action="tokenAction">

<s:textfield label="Name" name="name"></s:textfield>

<s:textfield name="age" label="Age"></s:textfield>

<s:token name="token"></s:token>





package roseindia.action;

import com.opensymphony.xwork2.ActionSupport;

public class TokenAction extends ActionSupport {

private String name;

private String age; 

public String getName() {

return name;


public void setName(String name) { = name;


public String getAge() {

return age;


public void setAge(String age) {

this.age = age;


public String execute() throws Exception {

return SUCCESS;  }


3_ struts.xml


<constant name="struts.enable.DynamicMethodInvocation" value="false" />

<constant name="struts.devMode" value="false" />

<package name="roseindia" extends="struts-default" namespace="/">

<action name="tokenAction" class="roseindia.action.TokenAction">

<interceptor-ref name="token" />

<interceptor-ref name="basicStack"/>

<result name="success" >/success.jsp</result>

<result name="invalid.token">/index.jsp</result>




4_ success.jsp

<%@ taglib uri="/struts-tags" prefix="s" %>





Name : <s:property value="name"/><br>

Age : <s:property value="age"/>







Download Select Source Code

Related Tags for Struts2.2.1 token tag example.: