Assuming the codes and the tag definitions in .tld file are working well, I need to run the application to perform the testing to check whether the custom tag can be applied on the jsp file successfully. After I restarted the Tomcat server, what I received are the following stakctrace appeared on the jsp file:
Stacktrace:] with root cause The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location] at org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:60) at org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:44) at org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:48) at org.apache.jsp.linking2_jsp._jspx_meth_g_005fsearch_005f0(linking2_jsp.java:108) ... ... Jun 17, 2013 11:37:29 AM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [jsp] in context with path [/TagList] threw exception [An exception occurred processing JSP page /linking2.jsp at line 10 7: <title>Insert title here</title> 8: </head> 9: <body> 10: <g:search term="Struts Tutorial"/> 11: </body> 12: </html>
I did some research on google and I found the solution from here: The Struts dispatcher cannot be found error. I added the following lines in WebContent/WEB-INF/web.xml:
<filter> <filter-name>struts-filter</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <filter-mapping> <filter-name>struts-filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
The root cause of the problem has been discussed in detailed on the website mentioned above.