- 浏览: 1115965 次
文章分类
- 全部博客 (379)
- S2SH (16)
- stuts2 (0)
- java语言 (81)
- JSP (17)
- <html>元素 (11)
- javaweb (4)
- web容器 (3)
- ext (23)
- javaScript (48)
- ant (1)
- liferay (1)
- sql (9)
- css (42)
- 浏览器设置 (3)
- office_world (1)
- eclipse (4)
- 其它 (28)
- 操作系统 (5)
- android (6)
- Struts2 (11)
- RegEx (3)
- mysql (5)
- BigDATA (1)
- Node.js (1)
- Algorithm (10)
- Apache Spark (1)
- 数据库 (5)
- linux (2)
- git (1)
- Adobe (3)
- java语言,WebSocket (1)
- Maven (3)
- SHELL (1)
- XML (2)
- 数学 (2)
- Python (2)
- Java_mysql (1)
- ReactJS (6)
- 养生 (4)
- Docker (1)
- Protocols (3)
- java8 (2)
- 书籍 (1)
- Gradle (2)
- AngularJS (5)
- SpringMVC (2)
- SOAP (1)
- BootstrapCSS (1)
- HTTP协议 (1)
- OAuth2 (1)
最新评论
-
Lixh1986:
Java并发编程:自己动手写一把可重入锁https://blo ...
Java之多线程之Lock与Condition -
Lixh1986:
http://win.51apps.com.cn/https: ...
temp -
ztwsl:
不错,支持很好
HttpServletRequest和ServletRequest的区别 -
guodongkai:
谢谢您能将知识精华汇编总结,让初学者们从原理中学会和提高。
javaScript之function定义 -
kangwen23:
谢谢了,顶顶
struts2中的ValueStack学习
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
-
发表评论
-
Spring之Interceptor之path patterns路径匹配规则
2018-12-26 11:20 8794Spring之Interceptor之path pattern ... -
Spring4.X之Constructor Injection 构造方法注入
2018-12-24 17:37 1582Spring4.X之Constructor Injection ... -
SpringMVC之@RequestMapping @ResponseBody 和 @RequestBody 注解的用法
2018-05-30 10:55 15861、@RequestMapping @RequestMappi ... -
Spring4.X之Bean的Scope
2017-11-06 16:29 1205https://docs.spring.io/spring/d ... -
Spring4.X之基于Java注解的配置(与SpringBoot的诞生)
2017-11-02 16:57 4157最近项目用到了SpringBoot,对其没有xml配置就可以运 ... -
03 - SpringBoot: Building a RESTful Web Service
2017-09-25 17:47 1032Building a RESTful Web Service ... -
02 - Difference between spring @Controller and @RestController annotation
2017-09-25 17:04 893Difference between spring @Con ... -
01 -Spring Framework: @RestController vs. @Controller
2017-09-25 16:45 752Spring MVC Framework and REST ... -
Spring - MVC 思维导图,让Spring不再难懂
2017-08-09 03:21 1082引用: http://www.iteye.com/news/3 ... -
hibernate merge与update区别
2017-04-18 15:38 2200今天做了个测试,写了 ... -
Struts2拦截器原理以及实例
2017-02-15 12:49 480Struts2拦截器原理以及实例 http://www.cnb ... -
Maven之POM之SSH之libs之configuration
2017-02-05 08:56 788Maven repo libs: Servlet API, ... -
Hibernate自定义查询
2014-02-24 16:29 1590public void addCarmera(Carmera ... -
Hibernate对象的生命周期
2013-07-10 16:32 1839一、情景描述 鉴于:hibernate是面向对象(实体、en ... -
通过配置struts.xml解决 struts2和 dwr兼容的问题
2012-11-20 10:20 2085众所周知,strust2 通过在 web.xml中配置 fil ...
相关推荐
随着struts的安全问题的暴露,原由Struts2+spring+hibernate构成的SSH2已经被越来越多的开发者所弃用,反而,由Spring+SpringMVC+Hibernate构成的SSH框架越来越受欢迎!这里提供了一个案例代码,希望对大家搭建环境...
SSH开源框架,全称为Struts2、Spring和Hibernate的组合,是Java开发中常见的Web应用框架。这个框架集合了三个强大的组件,旨在提供一个高效、灵活且可扩展的开发环境,帮助开发者快速构建企业级应用。Spring MVC是...
SSH,全称Spring、Struts和Hibernate,是Java Web开发中的一个经典组合,常用于构建企业级应用。这个环境的搭建涉及到多个组件的配置和整合,下面将详细讲解SSH环境的搭建过程及其核心知识点。 首先,Spring是SSH...
SSH是Java开发中的一种经典企业级应用框架,由Struts2、Hibernate和Spring三个开源框架组合而成。这个框架集合提供了模型-视图-控制器(MVC)架构模式,持久层管理,以及服务层的实现,使得开发高效且灵活。下面我们...
本主题将深入探讨如何使用SpringMVC和SSH(Struts2 + Hibernate + Spring)框架来实现文件的上传与下载。 首先,我们来看SpringMVC中的文件上传。SpringMVC是Spring框架的一部分,它提供了强大的MVC设计模式支持,...
- **配置文件**:包括Struts2的struts.xml,Spring的applicationContext.xml或springmvc-servlet.xml,以及Hibernate的hibernate.cfg.xml,这些文件定义了框架的行为和组件间的依赖关系。 通过SSH框架,网上购物...
SpringMVC是Spring框架的一部分,主要用于构建MVC(Model-View-Controller)架构的Web应用程序,而SSH2则指的是Struts2、Spring和Hibernate的集成,这三者分别处理表现层、业务逻辑层和数据持久化层。 在"springMVC...
SSH整合提供了完整的MVC架构,Oracle作为后端数据库,Mybatis或Hibernate处理数据访问,Spring提供业务逻辑管理,Struts2或SpringMVC负责前端请求处理,jQuery增强用户界面,而Lucene实现内部的全文搜索。...
SSH是Java开发中的一种经典架构组合,代表Spring、Struts和Hibernate这三个开源框架的结合。在本项目"SSH - SpringMVC4 + Spring4 + Hibernate4 + c3p0 + Mysql.zip"中,开发者使用了SpringMVC4作为表现层,Spring4...
本教程将深入探讨如何构建一个基于SpringMVC、Spring和Hibernate的完整应用程序,这是SSH框架搭建的第二步,重点在于搭建Hibernate部分并进行测试。 首先,Hibernate是一个对象关系映射(ORM)框架,它简化了Java...
SSH框架是Struts、Spring和Hibernate三个框架的集成,全称为Spring + Struts + Hibernate,是一种广泛应用的Java企业级开发框架组合。这种集成框架提供了一套完整的解决方案,旨在帮助开发人员快速构建可扩展、可...
2. **Struts1.x框架**:Struts1.x是MVC(Model-View-Controller)设计模式的实现,主要用于处理用户请求和展现视图。在SSH整合中,Struts1.x作为前端控制器,接收HTTP请求,调用业务逻辑,然后将结果传递给视图进行...
这个项目是一个基于Java语言开发的Web应用程序,采用SSM(Spring+SpringMVC+MyBatis)或SSH(Spring+SpringMVC+Hibernate)框架进行开发,使用MySQL作为数据存储,JSP作为页面开发。 项目的目标是构建一个高效、可靠...
SSH(Spring、Struts、Hibernate)是传统的Java Web开发框架,而SSM(Spring、SpringMVC、MyBatis)和SpringBoot是现代的Java开发工具。Vue.js则是一个流行的前端JavaScript框架,用于构建用户界面。这里提到...
6、SpringMVC和Struts2的区别 第二天 1、高级参数绑定 a)数组类型的参数绑定 b)List类型的绑定 2、@RequestMapping注解的使用 3、Controller方法返回值 4、SpringMVC中异常处理 5、图片上传处理 6、Json数据交互 7...
Spring、SpringMVC和Hibernate是Java开发中三大核心框架,它们的组合被称为SSH(Spring、Struts、Hibernate)集成框架,尽管在本例中Struts并未提及,但SpringMVC可以视为Struts的现代替代品。这个压缩包"Spring4,2...
在本项目中,我们探讨的是一个基于Spring MVC的SSH(Struts2、Spring、Hibernate)简单物流系统。这个系统是为大学生课程设计而构建的,它展示了如何将这些核心技术集成到一个实际的应用场景中,帮助学生理解Web开发...
SSH网上商城2018是一个基于SSH(Struts2、Spring、Hibernate)技术栈开发的电子商务平台项目。这个系统在2018年4月左右完成,提供了完整的网上购物功能,包括用户管理、商品浏览、购物车、订单处理等核心模块,适合...
SSH框架是Java Web开发中广泛使用的三大框架的组合,它们分别是Spring、Struts和Hibernate。这些框架协同工作,为开发者提供了强大的模型-视图-控制器(MVC)架构支持,提高了开发效率和代码的可维护性。下面我们将...