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

Struts2.2.1 Ajax div tag example.

In this section, we will introduce you to about the Ajax div tag. The div tag when used with Ajax refreshes the content of a particular section without refreshing the entire page.

 1- index.jsp




<a href="divpage.action">Ajax_Div_Tag_Example</a><br>



2_ div.jsp

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

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



<script type="text/javascript">

function toggleAlert(){



function toggleDisabled(e1)

{try {e1.disabled=e1.disabled? false: true;} 

catch (E){if(e1.childNodes&& e1.childNodes.length>0){

for(var x=0;e1.childNodes,length;x++){

toggleDisabled(el.childNodes[x]);   }  } } }



<s:url id="devResult" action="devResult.action"> </s:url>

<sx:div href="%{devResult}" label="Value of another page in div"></sx:div>

<sx:div id="div2" executeScripts="true">Value</sx:div>

<div id="formdata">

<s:form action="resultAction.action">

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

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

<sx:submit targets="div2" value="toggleAlert()" onclick="toggleAlert()" ></sx:submit>




errorText="Error in loaging"





3_ showInDiv.jsp

<%@page import="java.util.Date"%>




<body>Hi friends, this is another page data.<br>

<% Date today= new Date();

out.println(today); %>



4_ resultPage.jsp

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




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

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




package roseindia.action;

import com.opensymphony.xwork2.ActionSupport;

public class AjaxDivAction extends ActionSupport{

private String name;

private String age;

public String getAge() {

return age;


public void setAge(String age) {

this.age = age;


public String getName() {

return name;


public void setName(String name) { = name;


public String execute() {

return SUCCESS; } }

6_ struts.xml


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

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

<action name="divpage">



<action name="devResult" >

<result >showInDiv.jsp</result>


<action name="resultAction" class="roseindia.action.AjaxDivAction">

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




Download Source Code

Related Tags for Struts2.2.1 Ajax div tag example.: