Struts <html:img> Tag

In this Struts example, you will learn how to create a HTML img tag with Struts <html:img> tag. In order to use the Struts HTML Tags you need to include the following taglib directive in the jsp page.

<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> 

First create a new Dynamic Web Project and configure it as Maven Project. For Reference, Click Here

Add the following dependencies in pom.xml


1. Create JSP

Now we will create a HTML img tag using Struts’s HTML tag

Write the following code in img.jsp

<%@taglib uri="" prefix="html"%>
<title>Struts <Html:img> Img</title>
<html:img src="img/Struts.png"  width="150" alt="Struts" />

2. Struts Config

Write the following code in struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC 
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" 

3. Deployment Descriptor

Now configure the deployment descriptor. Here, we have asked the container to give our ActionServlet any request that matches the pattern *.do

Add the following configuration information in the web.xml file


4. Run Project

Now when you run the project, following screen will be displayed as in Figure 23.1

Figure 23.1 Figure 23.1

The folder structure of the example is shown below in Figure 23.2

Figure 23.2 Figure 23.2

You can download the source code of this example here.


One Response to Struts <html:img> Tag