正在加载图片...
4.4 Struts&spring 整合 与 Struts相似, Spring可以作为一个MvC实现。这两种框架都具有自己的优 点和缺点,尽管大部分人同意 Struts在MvC方面仍然是最好的。很多开发团 队已经学会在时间紧迫的时候利用 Struts作为构造高品质软件的基础 Struts具有如此大的推动力,以至于开发团队宁愿整合 Spring框架的特性, 而不愿意转换成 Spring mvc。没必要进行转换对您来说是一个好消息。 Spring架构允许您将 Struts作为Web框架连接到基于 Spring的业务和持 久层。最后的结果就是现在一切条件都具备了, 窍门1.使用 Spring的 Action Support 手动创建一个 Spring环境是一种整合 Struts和 Spring的最直观的方式。为了使 它变得更简单, Spring提供了一些帮助。为了方便地获得 Spring环境, org. springframework.web. struts. ActionSupport类提供了一个 getWebApplication Contexto方法。您所做的只是从 Spring的 Action Support而不是 Struts action类扩展您的动作,如清单1所示 清单1.使用 Action Support整合 Struts package ca. nExcel books actions import java. io IOException import javax. servlet Servletexception importjavax.servlethttpHttpservletrequEst importjavax.servlethttpHttpservletrespOnse import org. apache. struts action. actionError import org. apache. struts action. ActionErrors import org. apache struts action. action Form import org. apache. struts action. ActionForward import org. apache struts action Action Mapping import org. apache struts action. DynaActionForm import org. springframework context. ApplicationContext4.4 Struts&Spring 整合: 与 Struts 相似,Spring 可以作为一个 MVC 实现。这两种框架都具有自己的优 点和缺点,尽管大部分人同意 Struts 在 MVC 方面仍然是最好的。很多开发团 队已经学会在时间紧迫的时候利用 Struts 作为构造高品质软件的基础。 Struts 具有如此大的推动力,以至于开发团队宁愿整合 Spring 框架的特性, 而不愿意转换成 Spring MVC。没必要进行转换对您来说是一个好消息。 Spring 架构允许您将 Struts 作为 Web 框架连接到基于 Spring 的业务和持 久层。最后的结果就是现在一切条件都具备了。 窍门 1. 使用 Spring 的 ActionSupport 手动创建一个 Spring 环境是一种整合 Struts 和 Spring 的最直观的方式。为了使 它变得更简单,Spring 提供了一些帮助。为了方便地获得 Spring 环境, org.springframework.web.struts.ActionSupport 类提供了一个 getWebApplicationContext() 方法。您所做的只是从 Spring 的 ActionSupport 而不是 Struts Action 类扩展您的动作,如清单 1 所示: 清单 1. 使用 ActionSupport 整合 Struts package ca.nExcel.books.actions; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.DynaActionForm; import org.springframework.context.ApplicationContext;
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有