Editing struts-config.xml in a Struts Application

By: Gokul Verma Emailed: 1759 times Printed: 2452 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

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"
 "http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">

<struts-config>

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

    <form-bean      name="submitForm"
                    type="hansen.playground.SubmitForm"/>

  </form-beans>

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

    <action   path="/submit"
              type="hansen.playground.SubmitAction"
              name="submitForm"
              input="/submit.jsp"
              scope="request">
    <forward name="success" path="/submit.jsp"/>          
    <forward name="failure" path="/submit.jsp"/>          
    </action>

  </action-mappings>

</struts-config>

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:

Class

Actual name

ActionForm

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

Action

<action>Action


Struts Home | All Struts Tutorials | Latest Struts Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(8)


1. View Comment

really excellent explaynation

View Tutorial          By: dilip kumar at 2007-06-04 03:14:38
2. View Comment

crystal clear explanation

View Tutorial          By: digant at 2009-12-08 09:10:06
3. View Comment

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
4. View Comment

Can you please tell me about parameter and validate tag

View Tutorial          By: Atul at 2010-09-08 04:48:00
5. View Comment

it help me lot 2 understand what is struts-config file

View Tutorial          By: Amit Tomar at 2010-11-27 09:27:15
6. View Comment

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
7. View Comment

Thank u it helps me alot.....

View Tutorial          By: Ramya at 2012-02-22 10:16:14
8. View Comment

good example tnq...........

View Tutorial          By: SaidiReddy at 2012-06-09 12:03:09

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Gokul Verma
Creating the first application using Struts 2
Editing struts-config.xml in a Struts Application
Editing web.xml in a Struts Application
The directories and files of a Struts application
Downloading and installing Struts

More Tutorials in Struts
Configuring JDBC DataSources in Struts
Struts Classes
FAQ: Why was reload removed from Struts (since 1.1)?
FAQ: Why are my checkboxes not being set from ON to OFF?
Using JavaScript to submit a form in Struts
How to prepopulate a form in Struts
Simple example of using the requiredif Validator rule in Struts
Chaining actions in Struts
When is the best time to validate input in Struts
What is a Plug-in and how to use Java plug-ins with Struts?
7 Best Practices of Struts
Origin and Architecture of Struts
ActionErrors and ActionError in Struts
Tutorial on Struts Configuration File - struts-config.xml in Struts - from the book: Struts Survival Guide. Basics to Best Practices
Handling multiple buttons in HTML Form in Struts

More Latest News
Most Viewed Articles (in Struts )
Editing struts-config.xml in a Struts Application
What is Struts? Which Version of Struts to use?
Is Struts the most popular web application framework for Java?
What is a Model View Controller (MVC) Model?
History of Struts
WebWork 2 is now Apache Struts 2
Configuring JDBC DataSources in Struts
Struts Classes
Downloading and installing Struts
The directories and files of a Struts application
Editing web.xml in a Struts Application
Creating the first application using Struts 2
Struts 1 vs Struts 2
Model 1 Architecture
MVC Architecture (Model 2 Architecture)
Most Emailed Articles (in Struts)
What is a Model View Controller (MVC) Model?
History of Struts
Configuring JDBC DataSources in Struts
Is Struts the most popular web application framework for Java?
The directories and files of a Struts application
Editing struts-config.xml in a Struts Application
Struts 1 vs Struts 2
Creating Struts Modules
Using Multibox in Struts
ActionErrors and ActionError in Struts
Tutorial on Struts Configuration File - struts-config.xml in Struts - from the book: Struts Survival Guide. Basics to Best Practices
Handling multiple buttons in HTML Form in Struts
ForwardAction in Struts
Protecting JSPs from direct access in Struts
Handling Duplicate Form Submissions in Struts