Monday, August 22, 2011

Struts framework

1) What is the difference between perform and execute method in Struts Action class?

Perform method was first introduced in earlier versions of Struts which was declared as throwing java.lang.IOException and javax.servlet.ServletException. With this, the method is forced to handle any exception other than the above mentioned exceptions.

To remove this limitation, the later versions came up with the execute method with declaration of java.lang.Exception which allows the implementer to throw any kind of exception.

Reason for additional method is to keep the already developed code compatible with the latest versions of Struts.

2) How to use Struts tags?

i) First place the .tld file under the classpath
[Container looks for the TLD files under specific locations
a) Directly under WEB-INF
b) Directly under WEB-INF's sub-folders
c) Directly under any META-INF folder of a jar that is put under WEB-INF/jar
d) Directly under any sub-folder of a META-INF of a jar that is put under WEB-INF/jar
]
ii) Define the taglib tag in web.xml with defining taglib-uri speficying taglib-location
/struts-bean.tld
/WEB-INF/lib/struts-bean.tld
iii) Use this taglib-uri value in the page directive in JSP
<%@ taglib uri="" prefix=""%>
<%@ taglib uri="/struts-bean.tld" prefix="bean" %>

iv) Use the tags available in taglib

Since JSP 2.0, mentioning in web.xml is not required.
While loading container searches the TLD files and creates a map for all URI's and their TLD files. If you specify any taglib-uri = taglib-location entry in DD, then while construction of the -tld location map, container will use this DD entry.
This way when a tag is invoked, its tld can be approached for verification.


Useful topics :
Using popular display tag
Writing a custom tag
Using JSTL - already external link provided
How to access Map elements using struts tags
Tiles framework usage
How does .do get removed from the URL before the request is mapped to action class?