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" %>ADS_TO_REPLACE_1

<html>

<head><title>Struts_Token_Example</title></head>

<body><h1>Struts_Token_Example</h1><hr/>ADS_TO_REPLACE_2

<s:form action="tokenAction">

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

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

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

<s:submit></s:submit>

</s:form></body>ADS_TO_REPLACE_4

</html>

2_ TokenAction.java

package roseindia.action;

import com.opensymphony.xwork2.ActionSupport;

public class TokenAction extends ActionSupport {ADS_TO_REPLACE_5

private String name;

private String age; 

public String getName() {ADS_TO_REPLACE_6

return name;

}

public void setName(String name) {ADS_TO_REPLACE_7

this.name = name;

}

public String getAge() {ADS_TO_REPLACE_8

return age;

}

public void setAge(String age) {ADS_TO_REPLACE_9

this.age = age;

}

public String execute() throws Exception {ADS_TO_REPLACE_10

return SUCCESS;  }

}

3_ struts.xml

<struts>

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

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

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

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

<interceptor-ref name="token" />

<interceptor-ref name="basicStack"/>

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

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

</action>

</package>ADS_TO_REPLACE_14

</struts>

4_ success.jsp

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

<html>

<head><title>Struts_Token_Example</title>ADS_TO_REPLACE_15

</head>

<body><h1>Struts_Token_Example</h1><hr/>

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

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

</body>

</html>

index.gifADS_TO_REPLACE_17

value.gif

ADS_TO_REPLACE_18

success.gif

 ADS_TO_REPLACE_19

Download Select Source Code


Related Tags for Struts2.2.1 token tag example.:

Advertisements

Ads

 
Advertisement null

Ads