DispatchAction use category, the system slimming!

  DispatchAction use category, the system slimming! 

  In Struts you to the extent possible in the Action category not because they let you become bloated project, you can use org.apache.struts.actions.DispatchAction category to complete the necessary business logic centralized operation related to a category Action , in succession DispatchAction, you will no longer be redefined execute () method, but the preparation of your own business, execute () method in DispatchAction abstract class definition. 

  For example, we can define a succession DispatchAction AccountAction, some of which focus on management accounts and related operations, as follows: 

  Package com.fasttalk; 

  Import javax.servlet.http .*; 
  Import org.apache.struts.action .*; 
  Import org.apache.struts.actions .*; 

  Public class AccountAction extends DispatchAction ( 
  Public ActionForward login (ActionMapping mapping, 
  ActionForm form, 
  HttpServletRequest request, 
  HttpServletResponse response) 
  Throws Exception ( 
  / / Login related to the operation 
……
  ) 

  Public ActionForward logout (ActionMapping mapping, 
  ActionForm form, 
  HttpServletRequest request, 
  HttpServletResponse response) 
  Throws Exception ( 
  / / Logout related to the operation 
……
  ) 

  Public ActionForward method1 (ActionMapping mapping, 
  ActionForm form, 
  HttpServletRequest request, 
  HttpServletResponse response) 
  Throws Exception ( 
  / / Method1 related to the operation 
……
  ) 

…..
  ) 

  We do not redefine execute () method, but the definition of our own login (), logout () method, 
  These methods reception and execute () the same parameters, and also sent back ActionForward object. 

  DispatchAction use, we need to struts-config.xml definition: 

<ACTION
  Path = "/ account" 
  Type = "com.fasttalk.AccountAction" 
  Parameter = "method" 
  Name = "userForm"> 
  <FORWAR <span> 

  Method of Use: 

  Method1 parameters method to choose function = 

<%

  String dest = "account.do? Method1 method ="; 

  Response.sendRedirect (dest); 

%>

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags: ,

Releated Java Articles

Comments

Leave a Reply