By: Gokul Verma in Struts Tutorials on 2007年04月04日 [フレーム]
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
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
Most Viewed Articles (in Struts )
Handling Duplicate Form Submissions in Struts
Configuring JDBC DataSources in Struts
Simple example of using the requiredif Validator rule in Struts
Using JavaScript to submit a form in Struts
When is the best time to validate input in Struts
How to prepopulate a form in Struts
Guidelines for Struts Application Development
Latest Articles (in Struts)
Handling Duplicate Form Submissions in Struts
Guidelines for Struts Application Development
Configuring JDBC DataSources in Struts
When is the best time to validate input in Struts
Simple example of using the requiredif Validator rule in Struts
How to prepopulate a form in Struts
Using JavaScript to submit a form in Struts
FAQ: Why are my checkboxes not being set from ON to OFF?
FAQ: Why was reload removed from Struts (since 1.1)?
Handling Duplicate Form Submissions in Struts
Guidelines for Struts Application Development
Configuring JDBC DataSources in Struts
When is the best time to validate input in Struts
Simple example of using the requiredif Validator rule in Struts
How to prepopulate a form in Struts
Using JavaScript to submit a form in Struts
FAQ: Why are my checkboxes not being set from ON to OFF?
FAQ: Why was reload removed from Struts (since 1.1)?
© 2023 Java-samples.com
Tutorial Archive: Data Science React Native Android AJAX ASP.net C C++ C# Cocoa Cloud Computing EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Trends WebServices XML Office 365 Hibernate
Latest Tutorials on: Data Science React Native Android AJAX ASP.net C Cocoa C++ C# EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Cloud Computing WebServices XML Office 365 Hibernate