Struts 2、spring作業原理

10779 ワード


Struts2,spring    

Struts2    
  struts2     。 
Struts 2          3   :     FilterDispatcher、     Action              。
     FilterDispatcher Struts 2     ,                 。     Action                  。     Action          ,            ,      FilterDispatcher   。

Struts 2        Struts 1   , WebWork      ,   Struts 2 WebWork     。        :
1、        HTTP  。
2、  web.xml  ,    FilterDispatcher  。
3、  struts.xml  ,       Action    ,    IoC  ,     Aciton。
4、Action              ,         。
5、Action    ,  struts.xml             result,        。
6、  HTTP         。


Struts    ?      Struts? 
    : 
Struts     : 
 web            ActionServlet,ActionServlet  
struts-config.xml         ,             
 ActionServlet          ,       . 
-(1)          ActionMapping  ,     ,           ; 
-(2)  ActionForm     ,     ActionForm  ,             ActionForm   ; 
-(3)                .      ,   ActionForm validate()  ; 
-(4)  ActionForm validate()    null        ActionMessage ActuibErrors  ,          ; 
-(5)ActionServlet  ActionMapping                  Action,      Action     ,        ,    Action execute()  ; 
-(6)Action execute()      ActionForward  ,ActionServlet          ActionForward     JSP  ; 
-(7)ActionForward    JSP        ,     ; 

     : 
JSP、Servlet、JavaBean                        。                ,      ,        、              ,     ,Struts     。 

  Struts      3     :     、    、     

8. Struts validate        ? 
 struts              ,  FormBean  validate()      。 

9.   Struts      
MVC  : web               ActionServler。       ,      ActionForm     ,           ,ActionServler  Struts-config.xml                  ,       ActionForm  Validate()             Action,  Action   ,ActionServlet        ,     Action execute()  。Execute() ActionForm       ,      ,    ActionForward  ,ActionServlet         ActionForward     jsp  ,ActionForward     jsp       ,     。 

struts1 struts2          ,     : 
Action  : 
  ◆Struts1  Action         。Struts1                    。 
  ◆Struts 2 Action       Action  ,        ,             。Struts2    ActionSupport           。Action       ,   execute   POJO       Struts2 Action  。 
      : 
  ◆Struts1 Action               ,    Action             。       Struts1 Action    ,           。Action              。 
  ◆Struts2 Action              ,          。(   ,servlet                 ,               ) 
  Servlet   : 
  ◆Struts1 Action    Servlet API ,     Action    HttpServletRequest   HttpServletResponse     execute  。 
  ◆Struts 2 Action      ,  Action         。    ,Struts2 Action         request response。  ,                HttpServetRequest   HttpServletResponse    。 
     : 
  ◆  Struts1 Action        execute     servlet API(           )。       --Struts TestCase--     Struts1     (     )。 
  ◆Struts 2 Action       、    、       ,“    ”         。 
      : 
  ◆Struts1   ActionForm      。   ActionForm        。    JavaBean    ActionForm,               。  Bean(DynaBeans)        ActionForm   ,  ,           (  )     JavaBean(         javabean)。 
  ◆ Struts 2    Action        ,              。          ( )   rich    。Action      web    taglibs  。Struts2   ActionForm  。rich    ,      ,      /    。  ModelDriven      taglib POJO       。 
       : 
  ◆Struts1    JSTL,    JSTL EL。  EL        ,               。 
  ◆Struts2    JSTL,                   --"Object Graph Notation Language" (OGNL). 
        (view): 
  ◆ Struts 1    JSP              。 
  ◆Struts 2    "ValueStack"  , taglib              (view)       。ValueStack                         (view)。 
      : 
  ◆Struts 1 ActionForm       String  。Struts1  Commons-Beanutils      。        ,              。 
  ◆Struts2   OGNL      。             。 
    : 
  ◆Struts 1   ActionForm validate       ,    Commons Validator      。              ,        。 
  ◆Struts2    validate   XWork         。XWork                      ,   chain      
  Action     : 
  ◆Struts1           Request Processors(    ),        Action           。 
  ◆Struts2         (Interceptor Stacks)    Action         。            Action     


[b]spring mvc           ? [/b]
1  spring mvc          DispatcherServlet,                             。 
2.DispatcherServlet       HandlerMapping,       Controller. 
3.DispatcherServlet        Controller 
4.Controller         ,     ModelAndView 
5.Dispathcher       ViewResolver     ,  ModelAndView          
6.              。 

    : 
{AOP                  ,       ,              。   AOP  ,     (    、   、   )                ,                  。 
IOC                  ,                。            ,IOC         JNDI。          、     、   (singleton)     (straight construction),                。            (collaborator)。 
Spring    AOP  ,   IOC  。 Spring                。   Spring,    JavaBean             (    )。                         。} 




Spring          ,  7           。Spring            ,         、      bean    ,   1   。 

   Spring        (   )       ,                。         : 

☆     :       Spring        。           BeanFactory,         。BeanFactory        (IOC)                            。 

☆ Spring    :Spring           ,  Spring          。Spring          ,   JNDI、EJB、    、   、       。 

☆ Spring AOP:        ,Spring AOP                    Spring    。  ,        Spring             AOP。Spring AOP       Spring                   。     Spring AOP,     EJB   ,                   。

☆ Spring DAO:JDBC DAO                 ,                            。             ,                   (         )。Spring DAO     JDBC          DAO       。 

☆ Spring ORM:Spring          ORM   ,      ORM        ,     JDO、Hibernate   iBatis SQL Map。        Spring        DAO       。 

☆ Spring Web   :Web                    ,    Web            。  ,Spring       Jakarta Struts    。Web                              。 

☆ Spring MVC   :MVC             Web       MVC   。      ,MVC            ,MVC          ,     JSP、Velocity、Tiles、iText   POI。 

Spring             J2EE     ,                。Spring       :         J2EE                。    ,           J2EE    (Web   EJB)、      、        。 

IOC   AOP 

      (        )      :     ,           。               ,                     。  (  Spring      IOC   )           。 

     IOC    ,         ,                ,          。      IOC        。 




Spring     IOC        2    3   。 


        

       ,  AOP,       ,                          (         )     。AOP         ,                      。 

AOP   IOC        ,                          。             ,                  Java           。  AOP    ,             ,                     。  ,     Java              ,           。  ,  Spring AOP                。 

AOP           Spring     、              。 

IOC    

Spring        org.springframework.beans  ,         JavaBean       。              ,                     。          BeanFactory   ,           ,             。BeanFactory             。 

BeanFactory         。 

□                       ,            。Singleton               。            。 

□                     。              ,       。 

bean        Spring    IOC      。IOC                     。                ,Spring      JavaBean                    。 

BeanFactory    

   org.springframework.beans.factory.BeanFactory        ,                。     BeanFactory     XmlBeanFactory,    XML          bean,    1   。 

   1. XmlBeanFactory 

BeanFactory factory = new XMLBeanFactory(new FileInputSteam("mybean.xml")); 

  XML        Bean        ,       bean   ,bean         。   BeanFactory    bean,     getBean()   ,        bean      ,    2   。 

   2. getBean() 

MyBean mybean = (MyBean) factory.getBean("mybean"); 

   bean         POJO (     JavaBean        )   FactoryBean。FactoryBean       Spring                    。 

IOC    

                     。          Spring       1        ,        ,        Spring IOC              (          )。 

                 。     ,                   : 

☆         ,           。 

☆         ,      ,                  ,       (      )。 

☆       ,                 。 

     

      ,         ,                      。                  。 

   3. CreditRatingInterface 

public interface CreditRatingInterface { 
public boolean getUserCreditHistoryInformation(ICustomer iCustomer); 
} 

   3                     。             Customer   。         CreditRating     。 

   4. CreditLinkingInterface 

public interface CreditLinkingInterface { 

public String getUrl(); 
public void setUrl(String url); 
public void linkCreditBankAccount() throws Exception ; 

} 

                  (      )     ,           。             ,        getUrl()      。URL   Spring     bean       ,       。         CreditLinking     。 

   5. EmailInterface 

public interface EmailInterface { 

public void sendEmail(ICustomer iCustomer); 
public String getFromEmail(); 
public void setFromEmail(String fromEmail) ; 
public String getPassword(); 
public void setPassword(String password) ; 
public String getSmtpHost() ; 
public void setSmtpHost(String smtpHost); 
public String getUserId() ; 
public void setUserId(String userId); 


         : 
        ①:          。 
        ②:          。(                  ,        ,    WC  WC) 
public class WC {  

    //     1   
    private static WC wc1 =null;  
  
    public static WC getInstance1() {  
if(wc1==null) 
{ 
Wc1=new WC(); 
} 
        return wc1;  
    }  

1.	           (  )  。 
2.      js  ,        。(            …) 
3. ajax  ?    ? 
4.         。 
5.      j2ee  ,      。 
6. Hibernate Session    ? 
a)	     session        session。        
7. Hibernate           Eager         ? 
8.           ,        。 
9.      ,     ? 
10.     ?bug  ?