Tuesday, December 22, 2009

Using struts 2 tags

In order to use the struts 2 tags in you .jspx files, you need to add the following lines to your source code at the beginning of your page.

For jspx files, add the following :


xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:s="/struts-tags"
version="2.0">

For jsp pages, add the follwing :

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


This will help you to use the prefix 's' in order to use the struts tags in your .jspx and jsp pages.

Struts 2 iterator tag sample

Here is a small example of using the iterator tag in struts 2.

    


Its a very simple example. I will keep posting more complex ones over here as and when i get a chance to work with them.



Signing Off
Ryan

Struts 2 environement setup

Here is a sample web.xml to add struts functionality to a web application. The most important part is the struts filter.

Remember to include the following jar files in the classpath to use struts 2 fuctionality. i.e. lib directory.

commons-logging-1.0.4.jar
freemarker-2.3.8.jar
ognl-2.6.11.jar
struts2-core-2.0.14.jar
xwork-2.0.7.jar

As is visible from the name of the struts jar file, these are the jar files that are required for struts 2. The dependencies of the jar files may change depending upon the version of struts you use. For now, these versions are compatible with each other.



    
        
            30
        
    
    
        struts2
        org.apache.struts2.dispatcher.FilterDispatcher
    
    
        struts2
        /*
    
    
        index.jsp
    




This should be enough to set up the environment for Struts 2. Additional functionality can be provided to struts 2 by adding more jar files, but i am not concerned with that in this post. As of now, i just want to be able to have the bare minimum environmental settings for creating a struts 2 application, and this resolves my problem.

Signing Off
Ryan Sukale