Configure the Struts Tag Libraries

In Struts framework, you always need to configure the Struts tag libraries in order to access it in view page (JSP). There are two ways to configure it.

1. Strut Tag Libraries Manual Configuration

The manual configuration is the old and classic way, used in Struts version <= 1.1 and Servlet < 2.3 container. Download all the Struts dependencies, make sure the following “tld” files are copy to WEB-INF folder, you can find these files in the downloaded Struts library.

  • struts-bean.tld
  • struts-html.tld
  • struts-logic.tld
  • struts-tiles.tld

Declare the taglib uri in web.xml
web.xml

...
<taglib>
     <taglib-uri>
	  http://struts.apache.org/tags-bean
     </taglib-uri>
     <taglib-location>
	  /WEB-INF/struts-bean.tld
     </taglib-location>
</taglib>
<taglib>
     <taglib-uri>
	  http://struts.apache.org/tags-html
     </taglib-uri>
     <taglib-location>
	  /WEB-INF/struts-html.tld
     </taglib-location>
</taglib>
<taglib>
     <taglib-uri>
	  http://struts.apache.org/tags-logic
     </taglib-uri>
     <taglib-location>
	  /WEB-INF/struts-logic.tld
     </taglib-location>
</taglib>
<taglib>
     <taglib-uri>
	  http://struts.apache.org/tags-tiles
     </taglib-uri>
     <taglib-location>
	  /WEB-INF/struts-tiles.tld
     </taglib-location>
</taglib>
<taglib>
     <taglib-uri>
	  http://struts.apache.org/tags-nested
     </taglib-uri>
     <taglib-location>
	  /WEB-INF/struts-nested.tld
     </taglib-location>
</taglib>
...

Now you can access it in JSP page. The JSP’s @taglib uri have to match with web.xml <taglib-uri>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>

Actually, you can define your own taglib uri name, for example

web.xml

...
<taglib>
     <taglib-uri>
	  customer-anything/tags-bean
     </taglib-uri>
     <taglib-location>
	  /WEB-INF/struts-bean.tld
     </taglib-location>
</taglib>
...

Then access it via your custom taglib uri name.

<%@ taglib uri="customer-anything/tags-bean" prefix="bean" %>

2. Strut Tag Libraries Automatic Configuration

This is the easy way, and used in Struts version 1.2, 1.3 and Servlet 2.3/2.4 container only. You do not need to define the “tlds” details in web.xml anymore, just include the struts-taglib.jar in your project classpath or copy it to WEB-INF/lib folder.

All the “tld” details are define inside the “struts-taglib.jar\META-INF\tld” folder. During deployment, the struts-bean.tld, struts-html.tld, struts-logic.tld and struts-tiles.tld will deploy automatically. However, you can access it via the following “pre-fixed uri” name only. In this method, you are not allow to change the “taglib uri” name.

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>

FAQ

Q : Look like the “taglib uri” is pointing to Apache website, how about the client has NO internet access?
A : The taglib uri is define in “struts-taglib.jar\META-INF\tld” folder, it’s just a project uri name, not pointing to Apache website, you still can access it even in no internet access environment.

Q : Can the manual configuration work in latest Struts 1.2 or 1.3?
A : Yes, Struts is backward compatible, the old way is still support in Struts 1.2 and 1.3.

Q : Which method is the best?
A : It’s depend, the automatic configuration is only worked in Servlet 2.3/2.4 container. If you are allow to choose, please go to the automatic method, why you want to copy the tld files manually?

Reference

Tags :

About the Author

mkyong
Founder of Mkyong.com and HostingCompass.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

  • Pingback: ionizer payment plan()

  • Pingback: water ionizers()

  • Pingback: electrician 08080()

  • Pingback: h osborne auto electricians()

  • Pingback: house blue()

  • Pingback: alkaline water brands()

  • Pingback: cincinnati plumbing contractors()

  • Pingback: heating and plumbing contractors()

  • Pingback: you can check here()

  • Pingback: more helpful hints()

  • Pingback: electricians bible lite()

  • Pingback: b&q electricians rods()

  • Pingback: pay day loans()

  • Pingback: pay per day loans plan()

  • Pingback: Instagram volgers kopen()

  • Pingback: water ionizers()

  • Pingback: water ionizer()

  • Pingback: laane penge()

  • Pingback: car parking()

  • Pingback: parking()

  • Pingback: mobile porn()

  • Pingback: DIRECTV()

  • Pingback: Blue Coaster33()

  • Santosh

    I’m using maven in my application. Do i require to keep struts-tag.jar file in WEB-INF/lib folder.

    • murali

      yeah u can either keep struts-tag.jar file in WEB-INF/lib folder or set prjct class path to struts-taglib.jar -murali

      • santosh

        Thank you sir

  • Santosh

    I’m using Maven for my Application. Do i require to keep my struts-tag.jar in WEB-INF/lib folder.

  • vishwas

    I made my own tld and i want to give uri to my tld like that of apache tld, pointing to some website(http://struts.apache.org/tags-bean), that is, whenever somebody uses my tld he/she should give uri which looks like pointing to some website.

    How to do that?

  • gasser

    Hi,
    am trying to use this example but am not using Maven, but i got an error “Cannot find bean: “HelloWorldForm” in any scope”so please advice:-

    logs
    —-

    [9/26/12 9:29:25:500 GMT+02:00] 00000020 ServletWrappe E SRVE0068E: Uncaught exception thrown in one of the service methods of the servlet: /HelloWorld.jsp. Exception thrown : javax.servlet.ServletException: Cannot find bean: “HelloWorldForm” in any scope
    at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:660)
    at com.ibm._jsp._HelloWorld._jspService(_HelloWorld.java:76)
    at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:88)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1217)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:660)
    at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:535)
    at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:122)
    at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:248)
    at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionProcessor.handleRequest(AbstractJSPExtensionProcessor.java:295)
    at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:325)
    at com.ibm.ws.webcontainer.extension.DefaultExtensionProcessor.handleRequest(DefaultExtensionProcessor.java:630)
    at com.ibm.ws.wswebcontainer.extension.DefaultExtensionProcessor.handleRequest(DefaultExtensionProcessor.java:113)
    at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3574)
    at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:269)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:831)
    at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1478)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:133)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:457)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:515)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:300)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:271)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:196)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:751)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:881)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1551)
    —- Begin backtrace for Nested Throwables
    javax.servlet.jsp.JspException: Cannot find bean: “HelloWorldForm” in any scope
    at org.apache.struts.taglib.TagUtils.lookup(TagUtils.java:864)
    at org.apache.struts.taglib.bean.WriteTag.doStartTag(WriteTag.java:233)
    at com.ibm._jsp._HelloWorld._jspx_meth_bean_write_0(_HelloWorld.java:94)
    at com.ibm._jsp._HelloWorld._jspService(_HelloWorld.java:68)
    at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:88)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1217)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:660)
    at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:535)
    at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:122)
    at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:248)
    at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionProcessor.handleRequest(AbstractJSPExtensionProcessor.java:295)
    at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:325)
    at com.ibm.ws.webcontainer.extension.DefaultExtensionProcessor.handleRequest(DefaultExtensionProcessor.java:630)
    at com.ibm.ws.wswebcontainer.extension.DefaultExtensionProcessor.handleRequest(DefaultExtensionProcessor.java:113)
    at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3574)
    at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:269)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:831)
    at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1478)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:133)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:457)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:515)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:300)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:271)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:196)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:751)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:881)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1551)

    • gasser

      sorry .. plz ignore the above message cause i wrote in wrong thread

  • Pingback: Project 4o | Vaniazig's Blog()

  • Pingback: The absolute uri: http://struts.apache.org/tags-bean cannot be resolved in either web.xml or the jar files deployed with this application. | struts()