Tell a friend
Link to us
Bookmark Us
Total Members
      Members: 87081
Sitemap Forum Chat
 
JSP Home
JSP Members (19554)
JSP Member Articles ( 11 )
JSP Discussion (77)
JSP Q & A ( 97 )
- JSP Ask Question
- JSP Questions
- JSP Unanswered Questions
JSP Resources
JSP Source Code (172)
JSP Articles (34)
JSP Blogs (338)
JSP Jobs (40)
JSP Components (10)
JSP Books (10)
JSP Websites (13)
JSP News (12)

 
Resource Directory
Beans (0)
Books & Media (0)
Community (0)
Graphics & Charts (1)
JSP Videos (0)
JSP Web Hosting (0)
Other JSP Sites (0)
References (0)
Software & Server (0)
Tag Libraries (0)
Tutorials & Code Snips (0)
Web Applications (1)

 
GROUP INFO
Members: 19554
Access Type: Anyone can join

 

 
LEARNING CENTER
TUTORIALS
.NET
.NET Tutorial
ASP Tutorial
ASP.NET Database Tutorial
ASP.NET Development Tips
ASP.Net Security,Internationalisation And Deployment
ASP.NET Server Controls Tips
ASP.NET Tutorial
C Sharp Tutorial
LINQ Tutorial
Web Development
Flex Tutorial
HTML Tutorial
Javascript Tutorial
Learn AJAX Tutorial
PHP Tutorial
Software Development
Database Tutorial
SQL Tutorial
UML Tutorial
Java
Ant Tutorial
EJB 3 Tutorial
Grails Tutorial
Hibernate Tutorial
Java 1.6 Tutorial
Java Tutorial
Java Web Component Tutorial
Java XML Tutorial
JDBC Tutorial
JDK1.5 Tutorial
JSF Tutorial
JSP And J2EE Design Tutorial
JSP Tutorial
Service-Oriented Architecture (SOA) Tutorial For Managers
Spring Tutorial
Struts Tutorial
Tomcat Tutorial

RESOURCES
Q & A (531 )
Source Code (3276 )
Articles (365 )
Books (373 )
Components (1647 )
News (898 )
Websites (1208 )

SUBMISSIONS
Submit Article
Submit Website
Submit News
Submit Source Code
Submit Component

COMMUNITY
Authors
Members Directory
Discussion Forum
Chat

SITE
About Us
Sitemap
Search
Contact Us
Feedback
Tell a Friend
Advertise

 

Home > JSP > Member Articles > Fundamentals >
 

Struts Tutorial - Part 3


  Author : Visualbuilder
  Date Published : 09/7/2007
  Accessed : 12837
   visualbuilder
<< Back  Next >> 

The Struts new CoR(Chain of Responsibility) structure gives us more flexibility to add our commands in between the request processing and also with less effort. All the user needs is to extend org.apache.struts.chain.commands.ActionCommandBase class and override the execute() method in it.


 


The below example will demonstrate how do we insert our own command objects in the existing Struts CoR without changing the actual flow and the ComposeableRequestProcessor will call the file implicitly. For any type of addition and deletion of the commands only the chain-config.xml file is changed and the Struts automatically take care of the flow.


 


(1) Struts-config.xml


 


<?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 Bean Definitions -->
<form-beans>
    <form-bean name="inputForm" type="com.visualbuilder.InputForm" />


</form-beans>
<!-- ========================================= Global Exception Definitions -->
<global-exceptions></global-exceptions>
<!-- =========================================== Global Forward Definitions -->
<global-forwards></global-forwards>
<!-- =========================================== Action Mapping Definitions -->
<action-mappings>
    <action
    path="/submit"
    type="com.visualbuilder.SubmitAction"
    name="inputForm"
    scope="request"
    validate="false"
    input="/index.jsp"
/>
 
</action-mappings>


<!-- =========================================== Controller Mapping Definition -->
<controller contentType="text/html;charset=UTF-8" locale="true" debug="1" nocache="true" processorClass="org.apache.struts.chain.ComposableRequestProcessor" />

<!-- ======================================== Message Resources Definitions -->
<message-resources parameter="MessageResources" />


</struts-config>


 


(2) CustomCommand.java File


 


Note:- The following file is created for the command object. If it returns true it means some exception occurred so it wont call the next Command in the chain and returns to the input jsp file.


 


package com.visualbuilder.command;


 


import org.apache.struts.chain.commands.ActionCommandBase;
import org.apache.struts.chain.contexts.ActionContext;


 


public class CustomCommand extends ActionCommandBase {


@Override
public boolean execute(ActionContext ctx) throws Exception {


    boolean result=true;
        System.out.println("Called the logic for the Custom Command");
    return false;
    }


}


 


(3) Chain-config.xml file


 


Note :- The following command will be added in the chain-config.xml file anywhere in the process-action chain.


 


<!-- Execute the Custom Command for this request -->
<command className="com.visualbuilder.command.CustomCommand"/>


 


Pages   << Back  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  Next >>  Next: Part 17: Security in Struts >>

 
   Printer Friendly
   Email to a friend
   Add to my Favourites  Report Bad Submissions  Submit Feedback
  Download PDF version
 
                 Click each image to add
this page to each site.
 
Related Articles of JSP
Previous Article    -     Random Articles    -     Next Article
 
 
 
 
 
 
 
 
Welcome Guest Signup
Member's Panel
EMAIL
PASSWORD
Forgot your password?
New User? Click Here!
 
Resend Activation Email!

SEARCH
 



 
 
 
 
 


Home | Login | About Us | Contact Us | Privacy Policy | Advertising | Feedback Please

Warning: Unknown(): write failed: Disk quota exceeded (122) in Unknown on line 0

Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0