Online Hibernate Training just in Rs. 1000

One week online training in Hibernate ORM framework. Learn Hibernate Framework and enhance your skills. Best Online Hibernate training at 90% discount. Join Now!! Offer is valid Only for limited Period!!! Online Training

Developing Struts PlugIn

This article show you how to develop custom Struts PlugIn and incorporate in your Struts Web Applications.


Struts 2 Tutorial and Examples Struts General Availability - released Login form in Struts2 version 2.3.16 Struts 2 Login Application Struts 2 version released Struts 2 version released Struts 2 Hello World Annotation Example Struts Roseindia Struts 2 Tutorial: Easy steps to learn Struts 2 Difference between Struts and Spring Apache Struts launched to fix vulnerable Feature Struts2 Application in Eclipse: Running the application in Eclipse IDE Struts 2 Hello World Application using Eclipse Interceptors in Struts 2 Struts 2 Action Tag Struts 2 in Agile Development Environment Struts 2 UI Tags Generic Tags Creating own Interceptor What are Interceptors in Struts 2 and how do they work? Results Value Stack / OGNL Action in Struts 2 Framework Struts 2 Interceptors Struts Maven - How to use Maven dependency of Struts Download Struts How Struts 2 Framework works? Architecture of Struts 2 Framework Features and Enhancements in Struts Struts 2 Tutorials - Struts version Struts 1 Tutorial and example programs Struts Tutorial What is Struts Struts Flow Diagram Step By Step Struts Tutorial Struts 2 Login Form Example Struts Video Tutorials Struts 2 Hello World Example Introduction to Struts 2 Framework Downloading and Installing Struts 2.3.8 In Struts What is Model? What is Struts? Download Struts What is Struts Framework? Struts Framework Latest Version of Struts Framework Downloading Struts Official example Struts 2.3.8 released with new features Struts 2.3.8 Tutorials and Examples Hibernate4 Struts Integration

Developing Struts PlugIn


This article shows you how to develop custom Struts PlugIn and incorporate in your Struts Web Applications. After completing this tutorial you will be able to create your own custom PlugIn for your web application. Struts PlugIn allows the programmer to enhance their web applications. There are many PlugIns available for struts e.g. Struts Tiles PlugIn, Struts Hibernate PlugIn, Struts Spring PlugIn etc. Beside these available PlugIn you can create your own PlugIn.

Understanding PlugIn

Struts PlugIns are configured using the <plug-in> element within the Struts configuration file. This element has only one valid attribute, 'className', which is the fully qualified name of the Java class which implements the org.apache.struts.action.PlugIn interface.

For PlugIns that require configuration themselves, the nested <set-property> element is available.

The plug-in tag in the struts-config.xml file is used to declare the PlugIn to be loaded at the time of server start-up. Following example shows how to declare the Tiles PlugIn:

<plug-in className="org.apache.struts.tiles.TilesPlugin">

The above declaration instructs the struts to load and initialize the Tiles plugin for your application on startup. 



Writing Struts PlugIn Java Code

In this example we write HelloWorld Struts PlugIn example that will give you idea about creating, configuring and checking Struts PlugIn. Our HelloWorld Stuts PlugIn contains a method called Say Hello, which simply returns HelloWorld message.

Here is code of HelloWorld Struts Plugin: 


import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.apache.struts.action.PlugIn;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.config.ModuleConfig;

@author Deepak Kumar
* @Web
* @Email [email protected]

public class HelloWorldStrutsPlugin implements PlugIn {

  public static final String PLUGIN_NAME_KEY 
  = HelloWorldStrutsPlugin.class.getName();

 public void destroy() {
  System.out.println("Destroying Hello World PlugIn");

 public void init(ActionServlet servlet, ModuleConfig config
throws ServletException {
  System.out.println("Initializing Hello World PlugIn");
 ServletContext context = null;
 context = servlet.getServletContext();
 HelloWorldStrutsPlugin objPlugin = new HelloWorldStrutsPlugin();
 context.setAttribute(PLUGIN_NAME_KEY, objPlugin);


  public String sayHello(){
  System.out.println("Hello Plugin");
  return "Hello Plugin";

Configuring PlugIn

To configure the plugin add the following line your struts-config.xml file.

<plug-in className="">

Calling PlugIn From JSP Page

Here is the code for calling our PlugIn from jsp page.

<[email protected] contentType="text/html" import="java.util.*,*" %>

ServletContext servletContext = this.getServletContext();

HelloWorldStrutsPlugin plugin= (HelloWorldStrutsPlugin) servletContext.getAttribute

String strMessage = plugin.sayHello();


Message From Plugin: <%=strMessage%>

Building and Testing

Use ant tool to build the application and then deploy on the server. Enter the url http://localhost:8080/strutstutorial/pages/plugin.jsp in your browser. It display "Hello Plugin" message. Your server console also should display "Hello Plugin" message.

In this section we learnt how to develop simple struts plugin, configure, deploy and test.


Share on Google+Share on Google+

Developing Struts PlugIn

Posted on: July 14, 2006 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: Developing Struts PlugIn   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image