Using struts2-jquery for Ajax

Now struts2 is providing support for the most popular client side javascript JQuery using plugin (struts2-jquery-plugin-2.5.1.jar). you can implement ajax based funcationalities into your application without any effort and without writing any other javascript. strut2 was using dojo based support for ajax in pervious version but now they have implemented JQuery based ajax features. you need to download struts2-jquery-plugin-2.5.1.jar and set it in your application's classpath.
To support the JQuery based fucntionality, you need to include extra jsp taglib into you jsp page. Following is the simple exambple using JQuery plugin in JSP page.


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

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



    <sj:head jqueryui="true" jquerytheme="redmond" />



    <sj:a id="ajaxlink" 







        Run AJAX Action


    <div id="result">Result will be here.</div>


    <img id="myDefaultIndicator" src="ajax-loader.gif" alt="Loading..." style="display:none"/>



JSP page to be shown for result "ServerTime.jsp"
<%=""+new java.util.Date()%>

Action class ""
import java.util.Date;
import com.opensymphony.xwork2.ActionSupport;
public class ServerTime extends ActionSupport {
    public String execute(){
        System.out.println("Server time checked");
        try {
        } catch (InterruptedException e) {
        return SUCCESS;


<?xml version="1.0" encoding="UTF-8" ?>
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    <constant name="struts.devMode" value="true" />
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <package name="/" extends="struts-default">
        <action name="ServerTime" class="ServerTime">

Popular Posts