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 >

Using WildCards in ActionMapping Tutorial

Meyyappan Muthuraman user avatar by
Meyyappan Muthuraman
·
Jun. 15, 12 · · Tutorial
Like (0)
Save
Tweet
17.97K Views

Join the DZone community and get the full member experience.

Join For Free

In this tutorial you will learn see how to reduce the number of action mappings by using wildcard characters. Here is an example of struts configuration file using wildcard character.

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd">

<struts-config>

<form-beans>
    <form-bean name="SampleReportForm" type="com.vaannila.reports.SampleReportForm"/>
</form-beans>

<action-mappings>
    <action path="/*Action" type="com.vaannila.reports.{1}Action" name="{1}Form">
        <forward name="success" path="/{1}.jsp" />
    </action>
</action-mappings>

</struts-config>

Here the value of the path attribute contains a wildcard character. The value that matches the asterick(*) in the request URL will be substituted instead of '{1}' in the other attributes.

Let's see with an example. In the index.jsp page the request URL is "/SampleReportAction". So according to the configuration the "SampleReport" matches the asterick, so it will be substituted instead of {1}. For this requset URL the Action class will be SampleReportAction and the ActionForm will be SampleReportForm and when the ActionForward value is success the user will be forwarded to SampleReport.jsp page.

The index.jsp page contains a Generate Report button, which when clicked forwards the request to the SampleReportAction URL, then invokes the SampleReportAction class and displays the SampleReport.jsp page back to the user.

<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<html:form action="/SampleReportAction">
<html:submit value="Generate Report" />
</html:form>
</body>
</html>

Here is the sample report.

You can download the source code of this example by clicking on the Download link below.

Source: Download

War: Download

Download Requests Attribute (computing) WAR (file format) Links

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • JUnit 5 Tutorial: Nice and Easy [Video]
  • Transactions vs. Analytics in Apache Kafka
  • Making Machine Learning More Accessible for Application Developers
  • How To Integrate Event Streaming Into Your Applications

Comments

Partner Resources

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