`

SSH之Struts2 VS. SpringMVC

    博客分类:
  • S2SH
阅读更多


Struts 2 vs SpringMVC - Battle of the Frameworks - Isos Technology

Over the years in my work as a consultant, I’ve worked with several companies that were looking to convert their legacy systems to a web-based solution. Once they selected Java (great choice!) as their language, their next question is usually, “What Java framework should we use?”

In my experience, it usually comes down to Struts 2 or SpringMVC. I have worked extensively with both of these frameworks, so I will compare and contrast them for you. Keep in mind that there really isn’t a definitive “correct” framework to choose. You should look at your options, the dynamics of your development team and what you are trying to accomplish before you choose a framework. I’m hoping that this will help guide you in your decision making.

SpringMVC

Spring is basically a Java framework that allows you to create complex web applications through simple components and configurations. There are other aspects of Spring that you can use independently of SpringMVC, such as dependency injection and aspect-oriented programming. For the purposes of this article, we don’t need to talk about those because they can be used with SpringMVC or Struts 2. In my experience, they work really well with either.

SpringMVC is part of the Spring framework that is used for handing and processing web-based requests. It follows the basic MVC (Model-View-Controller) pattern. Spring-created JavaBeans are the model. The controller is the DispatcherServlet, which handles all requests and passes them to the corresponding controller. A nice feature is that you can use annotations to handle this requirement instead of using the infamous application-context.xml file. Anyone who used Spring in the early days knows that this file can get large quickly. Breaking this context file into smaller files just makes it more complicated. Anyway, the last piece is the view, which is usually composed of JSPs. However, if you are developing webservices the view could be a number of things. We will come back to webservices later, but this is your basic layout of Spring and its components.


Struts 2

Struts 2 is also a Java request-based framework that allows you to create web applications. The Struts 2 framework follows the basic MVC pattern. The controller is called the ActionController. It is backed by mappings in a struts.xml file that allows requests to be forwarded to the appropriate action. In my experience, most people use EJBs or even Spring JavaBeans as their model. However, the view is important here because Struts 2 has its own view language. This is an advantage over SpringMVC in that you can just learn Struts 2 and you can build a Java framework from beginning to end, which helps with your development team’s learning curve. I have found that companies looking to ramp up quickly will go the Struts 2 route because it is easier to get up and running.

Now that we have a basic understanding of the frameworks, let’s compare and contrast the frameworks using a few of the web components and possible issues you would come across while learning and developing using these frameworks.


Ajax Support

Ajax has become a good technology for displaying dynamic content or field validation for web-based applications. In my work as a consultant, I have been fortunate to work with Ajax in both SpringMVC and Struts 2 environments. Struts 2 has built-in Ajax support so there is no need to import a third-party library. So if you are keeping score, Struts 2 has its own view language, controller and Ajax support. Again, once your learn Struts 2 you can pretty much develop a web application from beginning to end without the assistance of almost any other framework.

Although SpringMVC does not have native Ajax support, this just gives a more seasoned developer the ability to choose its Ajax library. This is especially important since your development team may already have knowledge or a preference for an Ajax library, allowing you to leverage that knowledge. For example, in one company that was switching to a SpringMVC environment, many of the developers were familiar with the Dojo Ajax library. So instead of switching to Struts 2 and learning a new Ajax library, they were able to use all the knowledge of Dojo and make the full learning curve of switching to SpringMVC a little easier. I would give the edge to Struts 2 here because it’s easier to hit the ground running, provided that your developers do not have any experience with Ajax libraries.


RESTful Webservices Support

In any request-based web application, it is becoming increasing popular to use RESTful webservices because they are easier to develop and maintain and startup costs are minimal. In a world where IT is seen more as a cost than an expense, this is pretty important. Most developers I have come across don’t know how RESTful webservices work; they just know how to write them. It has really become that simple.

In Struts 2, I found it a little difficult to set up RESTful webservices when I first learned it. We essentially needed 2 separate xml files (one for RESTful URLs and the re-direct and the second for the struts action mapping). Another hassle is that in your Java Action you don’t necessarily know that this is a RESTful webservice or if it is just a plain old Struts Action. This can be confusing to some less experienced developers.

In SpringMVC, RESTful webservices take advantage of annotations which not only makes webservices easier to identify, it also makes them easier to develop and maintain. The majority of your changes all happen in the Java class and you just have to touch one xml file once as opposed to Struts 2 where you need to edit 3 different places for adding or removing webservice. I really like the RESTful webservice support in SpringMVC with an assist from annotations because everything is one place and therefore development time is shorter.
Continuing Maintenance and Evolving Framework

Java in general is constantly evolving and its frameworks are no different. They are both open source so improvements and efficiencies are always on the horizon. I find that Struts 2 is a more mature technology in that the changes to the basic framework have been minimal. SpringMVC, and along with it Spring, is constantly changing and getting better. The issue is that your developers will have to constantly keep up with the technology in order to improve the application as Java grows, web browsers change and other improvements happen around the webspace. It only sounds daunting because most IT firms do not take this into account. They only care about fixing bugs and enhancing the application. Eventually, old technologies will die off and new technologies and techniques that make web applications perform more efficiently will replace them. In this regard, SpringMVC applications must be constantly monitored for improvements and upgrades are a must. This is less important for Struts 2 because the underlying framework is not changing much. So, something else to think about when choosing between SpringMVC and Struts 2 is the maintenance costs and how much your department can afford.


In Conclusion

These are just some of the things you can use when deciding between SpringMVC and Struts 2. Like I said in the beginning, there isn’t really a definitive answer to which one is better. However, in my opinion, I would say if you are looking for a stable framework you should choose Struts 2. If you are looking for a more robust framework, you should choose SpringMVC.



----------------------------------------------------------------------

The Difference between STRUTS 2 and SPRING MVC


Apache Struts 2 and SpringMVC, these two are the most popular and much talked about Java web frameworks today. Many of you might have worked with both of these frameworks, but which is one is better to use? What are the basic differences between both of these frameworks?

Well, Apache Struts 2 is an elegant and extensible framework that is used for creating enterprise-level Java web applications. It is designed to streamline the development cycle, starting from building to deployment and maintenance of the application. In Struts, the object that is taking care of a request and routes it for further processing is known as “Action”.

On the other hand, Spring MVC is a part of a huge Spring framework stack containing other Spring modules. This means that it doesn’t allow developers to run it without Spring, but the developers can run the Spring Core without Spring MVC. The Spring MVC (Model View Controller) is designed around a DispatcherServlet, which dispatches the requests to handler with configurable handler mappings, view resolution and theme resolution.

While the objects responsible for handling requests and routing for processing in Struts called an Action, the same object is referred as Controller in Spring Web MVC framework. This is one of the very first differences between Spring MVC and Struts2. Struts 2 Actions are initiated every time when a request is made, whereas in Spring MVC the Controllers are created only once, stored in memory and shared among all the requests. So, Spring Web MVC framework is far efficient to handle the requests than Struts 2.


If we talk about the features, Struts 2 and Spring MVC framework caters different level of business requirements. Let’s take a look at features offered by both of these frameworks.

Struts 2 features

    - Configurable MVC components, which are stored in struts.xml file. If you want to change anything, you can easily do it in the xml file.

    - POJO based actions. Struts 2 action class is Plain Old Java Object, which prevents developers to implement any interface or inherit any class.

    - Support for Ajax, which is used to make asynchronous request. It only sends needed field data rather than providing unnecessary information, which at the end improves the performance.

    - Support for integration with Hibernate, Spring, Tiles and so on.

    - Whether you want to use JSP, freemarker, velocity or anything else, you can use different kinds of result types in Struts 2.

    - You can also leverage from various tags like UI tags, Data tags, control tags and more.

    - Brings ample support for theme and template. Struts 2 supports three different kinds of themes including xhtml, simple and css_xhtml.


On the other hand, Spring MVC framework brings totally different set of features.

Spring MVC features

    - Neat and clear separation of roles. Whether it is controller, command object, form object or anything else, it can be easily fulfilled with the help of a specialized object.

    - Leverage from the adaptability, non-intrusiveness and flexibility with the help of controller method signature.

    - Now use existing business objects as command or form object rather than duplicating them to extend the specific framework base class.

    - Customizable binding and validation will enable manual parsing and conversion to business objects rather than using conventional string.

    - Flexible mode transfer enables easy integration with the latest technology.

    - Customizable locale and theme resolution, support for JSPs with or without Spring tag library for JSTL and so on.

    - Leverage from the simple, but powerful JSP tag library known as Spring tag library. It provides support for various features like data binding and themes.


Of course, Struts is one of the most powerful Java application frameworks that can be used in a variety of Java applications. It brings a gamut of services that includes enterprise level services to the POJO. On the other hand, Spring utilizes the dependency injection to achieve the simplification and enhance the testability.

Both of these frameworks have their own set of pros and cons associated with it.

Struts framework brings a whole host of benefits including:


    - Simplified design

    - Ease of using plug-in

    - Simplified ActionForm & annotations

    - Far better tag features

    - OGNL integration

    - AJAX Support

    - Multiple view options and more

However, the only drawback with Struts 2 framework is that it has compatibility issues and poor documentation.



On the other hand, Spring MVC provides benefits like:

    - Clear separation between controllers, JavaBeans models and views that is not possible in Struts.

    - Spring MVC is more flexible as compared to the Struts.

    - Spring can be used with different platforms like Velocity, XLST or various other view technologies.

    - There is nothing like ActionForm in Spring, but binds directly to the domain objects.

    - Code is also more testable as compared to the Struts.

    - It is a complete J2EE framework comprising of seven independent layers, which simplifies integration with other frameworks.

    - It doesn’t provide a framework for implementing the business domain and logic, which helps developers create a controller and a view for the application.


However, like any other technologies or platforms, Spring MVC too suffers from several criticisms related to the complexity of the Spring framework.


Final Verdict

Either framework is a great choice. However, if you’re looking for the stable framework, Struts 2 is the right choice for you. On the other hand, if you’re looking for something robust, SpringMVC is perfect. Ensure that you review your exact requirements before choosing the framework!


















-
http://www.cygnet-infotech.com/blog/struts-2-vs-springmvc






-
分享到:
评论

相关推荐

    新SSH(Spring+SpringMVC+Hibernate)框架结构的java web案例实践

    随着struts的安全问题的暴露,原由Struts2+spring+hibernate构成的SSH2已经被越来越多的开发者所弃用,反而,由Spring+SpringMVC+Hibernate构成的SSH框架越来越受欢迎!这里提供了一个案例代码,希望对大家搭建环境...

    SSH(struts2,Hibernate,Spring)整合及测试亲测可用所需jar包

    SSH(struts2,Hibernate,Spring)整合及测试亲测可用所需jar包.

    ssh框架的jar包(包括SpringMVC)

    ssh完整的jar包:spring+bibernate+struts和spring+springmvc+hibernate

    [信息办公]基于struts的图书管理系统_struts_ts.zip

    这个项目是一个基于Java语言开发的Web应用程序,采用SSM(Spring+SpringMVC+MyBatis)或SSH(Spring+SpringMVC+Hibernate)框架进行开发,使用MySQL作为数据存储,JSP作为页面开发。 项目的目标是构建一个高效、可靠...

    SpringMVC学习笔记整合搭建框架

    6、SpringMVC和Struts2的区别 第二天 1、高级参数绑定 a)数组类型的参数绑定 b)List类型的绑定 2、@RequestMapping注解的使用 3、Controller方法返回值 4、SpringMVC中异常处理 5、图片上传处理 6、Json数据交互 7...

    基于SSH(struts-spring-hibernate)开发的学生成绩管理系统

    基于SSH(struts-spring-hibernate)开发的学生成绩管理系统,附完整报告,SQL文件,环境为:eclipse+mysql+jdk1.8+tomcate8。运行均能通过,可以作为期末大作业。亲测好用,如果调不通的话,可以私信我~~ 该软件的...

    SSH mybatis springmvc lucene Jquery oracle等笔记总结.docx

    当初学习JAVA的时候的个人笔记总结,包含SSH SSI整合,ORacle, JQuery,lucene,spring,springmvc,struts,hibernate等框架的基本应用

    基于Spring+Struts2+Hibernate 的商城系统

    该电子商城系统功能包括顾客的购物车、订单管理和留言板,支持商品搜索;后台管理员的商品、订单、会员、系统管理等。 ...系统采用技术:Spring+Struts2+Hibernate+mysql+jQuery+Ajax+面向接口编程

    struts2,hibernate,spring,springmvc,mybatis

    ssh,ssm的案例源代码,详细注释,涉及到企业开发中的常用技术点。

    ssh_shop.7z基于ssh的,可运行,不要积分

    一个大型电商项目,内部涉及技术有:struts2、springmvc、nginx、redis、solr、mysql、购物车、svn、pageHelper、tomcat、ftp、富文本编辑器、单点登录、zookeeper等等

    [其他类别]Struts+Hibernate实现MVC_strutsmvc.zip

    这个项目是一个基于Java语言开发的Web应用程序,采用SSM(Spring+SpringMVC+MyBatis)或SSH(Spring+SpringMVC+Hibernate)框架进行开发,使用MySQL作为数据存储,JSP作为页面开发。 项目的目标是构建一个高效、可靠...

    ssh框架搭建基础项目

    本项目为struts2,springMVC,hibernate整合的一个基础项目,在eclipse中将此项目导入,并打开项目中的applicationContext.xml文件,根据自己的数据库(Mysql)来进行相关修改,保存后在tomcat8中运行即可,进入...

    ssh.rar_Sqljdbc4

    SSH(Struts,Spring,Hibernate或SpringMVC,Spring,Hibernate) Struts进行流程控制,Spring进行业务流转,Hibernate进行数据库操作的封装。

    Java Web 整合开发和项目实践(SSH).part3

    第2篇为表现层框架Struts技术,介绍了Struts2的工作原理、核心文件、数据校验与国际化、标签库、拦截器等。第3篇为持久层框架Hibernate技术,介绍了Hibernate的工作原理、核心文件、核心接口及相关插件的使用方法。...

    Java Web 整合开发和项目实践(SSH) 高清.part1

    第2篇为表现层框架Struts技术,介绍了Struts2的工作原理、核心文件、数据校验与国际化、标签库、拦截器等。第3篇为持久层框架Hibernate技术,介绍了Hibernate的工作原理、核心文件、核心接口及相关插件的使用方法。...

    基于SSM(spring+springMVC+MyBatis)开发的仓库管理系统

    推荐一下这个课设的姊妹篇-------------基于SSH(struts-spring-hibernate)开发的学生成绩管理系统,https://download.csdn.net/download/weixin_54626591/85192764 本系统为仓库管理系统,系统功能较为基础,同时...

    图书管理系统.zip

    2:Java环境,1.8 3:数据库环境:5(5.5和5.7均运行过) 4:tomcat:7 5:easy ui 1.5,hibernate用的是3的版本 本系统是整合了ssh框架的一个简单的图书管理系统,功能集合了,读者、管理员、书籍、书架、街还书信息...

    [信息办公]Struts图书馆管理系统_struts.zip

    这个项目是一个基于Java语言开发的Web应用程序,采用SSM(Spring+SpringMVC+MyBatis)或SSH(Spring+SpringMVC+Hibernate)框架进行开发,使用MySQL作为数据存储,JSP作为页面开发。 项目的目标是构建一个高效、可靠...

    Spring、SpringMVC和Mybatis框架整合包

    但是,我们在实际应用中发现,SpringMVC可以完全替代Struts,配合注解的方式,编程非常快捷,而且通过restful风格定义url,让地址看起来非常优雅。 另外,MyBatis也可以替换Hibernate,正因为MyBatis的半自动特点,...

Global site tag (gtag.js) - Google Analytics