Editing struts-config.xml in a Struts Application

By: Gokul Verma  

The mapping of the request (remember: <some-name>.do) to a specific Action and ActionForm class is done in the struts-config.xml file. This is the edited  file from "struts-blank" to suit a one-page application:







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

<!DOCTYPE struts-config PUBLIC
 "-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"


  <!-- ========== Form Bean Definitions ================= -->

    <form-bean      name="submitForm"


  <!-- ========== Action Mapping Definitions ============ -->

    <action   path="/submit"
    <forward name="success" path="/submit.jsp"/>          
    <forward name="failure" path="/submit.jsp"/>          



The struts-config.xml file -

As you can see the file contains two sections: the form-beans section, that lists the ActionForm beans, and the action-mappings.

In the form-beans section you give the bean a logical name (referred to in the action-mapping) and specify the path for the class file.

The action-mappings are the most interesting. The attributes given are these:

path - name of the request: "submit.do". You don't enter the ".do"-part here.
type - the path for the Action class file
name - is the logical name of the form bean (from the form-bean section)
input - validation errors should be shown on this page
scope - specifies how long the form bean should live. You may specify "session" instead.

The forward tag tells the servlet where to go if it receives either "success" or "failure" from the Action class. We'll return to this feature. In our simple case we always return to the same page.

It's wise to standardize on class names. I've used these simple conventions:


Actual name


<action>Form, where <action> is the action-path-name



Archived Comments

1. thank u...
itz exactly wht i m searching for..

View Tutorial          By: Vishal at 2016-01-23 12:07:25

2. good example tnq...........
View Tutorial          By: SaidiReddy at 2012-06-09 12:03:09

3. How are can open a .jsp page by making mapping in struts config file.
View Tutorial          By: Air Ticket at 2012-05-15 11:25:40

4. Thank u it helps me alot.....
View Tutorial          By: Ramya at 2012-02-22 10:16:14

5. i don't understand the input attributes can u please explain some more else
View Tutorial          By: dhanalakshmi at 2011-05-05 07:10:25

6. it help me lot 2 understand what is struts-config file
View Tutorial          By: Amit Tomar at 2010-11-27 09:27:15

7. Can you please tell me about parameter and validate tag
View Tutorial          By: Atul at 2010-09-08 04:48:00

8. it was very good explanation hope all links give such clear explaination
thank u very much

View Tutorial          By: ravi at 2010-08-26 10:19:48

9. crystal clear explanation
View Tutorial          By: digant at 2009-12-08 09:10:06

10. really excellent explaynation
View Tutorial          By: dilip kumar at 2007-06-04 03:14:38

Most Viewed Articles (in Struts )

Latest Articles (in Struts)

Comment on this tutorial