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.

Ads

Tutorials   
Struts 2 Tutorial and Examples Struts 2.5.10.1 General Availability - released Login form in Struts2 version 2.3.16 Struts 2 Login Application Struts 2 version 2.3.16.3 released Struts 2 version 2.3.15.3 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 2.3.15.2 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 2.3.15.1 Maven - How to use Maven dependency of Struts 2.3.15.1? Download Struts 2.3.15.1 How Struts 2 Framework works? Architecture of Struts 2 Framework Features and Enhancements in Struts 2.3.15.1 Struts 2 Tutorials - Struts version 2.3.15.1 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
Ads

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">
  <set-property
  property="definitions-config"
   value="/WEB-INF/tiles-defs.xml"/>
</plug-in>

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: 

package roseindia.net.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 http://www.roseindia.net
* @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="roseindia.net.plugin.HelloWorldStrutsPlugin">
</plug-in>

Calling PlugIn From JSP Page

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

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

ServletContext servletContext = this.getServletContext();


HelloWorldStrutsPlugin plugin= (HelloWorldStrutsPlugin) servletContext.getAttribute
(HelloWorldStrutsPlugin.PLUGIN_NAME_KEY);

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.

Advertisements

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

Advertisements

 

Discuss: Developing Struts PlugIn   View All Comments

Post your Comment


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

Ads

 

Ads