DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone >

Struts HTML Tag Tutorial

Meyyappan Muthuraman user avatar by
Meyyappan Muthuraman
·
Jun. 14, 12 · · Tutorial
Like (2)
Save
Tweet
128.23K Views

Join the DZone community and get the full member experience.

Join For Free

In this example you will learn how to use Struts HTML Tags. 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" %>

All the Struts HTML tags should be nested within the body of the <html:form /> tag. We will create a simple feedback form to see how the different Struts HTML Tags can be used. The feedback.jsp contains the following code.

<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Feedback Form</title>
</head>
<body>
<b>Feedback Form</b>
<hr>
<html:form action="/feedbackAction">
<table>
    <tr>
        <td>
            Name :
        </td>
        <td>
            <html:text name="feedbackForm" property="name" />
        </td>
    </tr>
    <tr>
        <td>
            Sex :
        </td>
        <td>
            <html:radio name="feedbackForm" property="sex" value="M" >
            M </html:radio>
            <html:radio name="feedbackForm" property="sex" value="F" >
            F </html:radio>
        </td>
    </tr>
    <tr>
        <td>
            Comments :
        </td>
        <td>
            <html:textarea cols="20" rows="5" name="feedbackForm"
            property="comments" />
        </td>
    </tr>
    <tr>
        <td>
            <html:submit />
        </td>
        <td>
            <html:reset />
        </td>
    </tr>
</table>
</html:form>
</body>
</html>

The name attribute of the HTML tag contains the Form Bean name. The property attribute of the HTML Tag contains the corresponding Form property.

Once the feedback is submitted by the user, the user will be forwarded to the success page. Here the feedback submitted by the user will be displayed. We use Struts Bean Tag do to this. We use Struts Logic Equal Tag to display Male if the user has selected M for sex and Female if the user has selected F for sex. In order to use the Struts Bean and Logic Tag you need to include the following taglib directives in the jsp page.

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

The success.jsp page contains the following code.

<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Feedback Form</title>
</head>
<body>
<b>Feedback Successfully Submitted.</b><br>
You have submitted the following feedback.
<table>
    <tr>
        <td>
            Name :
        </td>
        <td>
            <bean:write name="feedbackForm" property="name" />
        </td>
    </tr>
    <tr>
        <td>
            Sex :
        </td>
        <td>
            <logic:equal name="feedbackForm" property="sex" value="M"> Male </logic:equal>
            <logic:equal name="feedbackForm" property="sex" value="F"> Female </logic:equal>
        </td>
    </tr>
    <tr>
        <td>
            Comments :
        </td>
        <td>
            <bean:write name="feedbackForm" property="comments" />
        </td>
    </tr>
</table>
</body>
</html>

On executing the example the following page will be dispalyed to the user.

On submitting the feedback the following page will be dispalyed to the user.

You can download the source code of the Struts HTML Tags example by clicking on the Download link below.

Source :Download
Source + Lib :Download

 

HTML

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Blocking Ads on Your Network Using Raspberry Pi 3 + Fedora + Pi-hole
  • What Is Edge Compute? It’s Kind of Like Knitting Dog Hats
  • Kubernetes Service Types Explained In-Detail
  • Deploying Java Applications to AWS Elastic Beanstalk

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo