Friday, 4 March 2016

Difference Between Struts 2 and Spring 3.x

Better Support of UI Tag
You can also leverage from various tags like UI tags, Data tags, control tags and more.

Struts is pull based MVC while spring is PUSH based MVC

Poor documentation.........while  in spring we have good knowledge base

AJAX support in Struts 2

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.

Struts 2 provides built-in support to AJAX using Dojo Toolkit library. If you are new to Dojo, you may want to go through the Introduction of DOJO Toolkit.

Struts 2 comes with powerful set of Dojo AJAX APIs which you can use to add Ajax support. In order to add Ajax support, you need to add following JAR file in your classpath:
struts2-dojo-plugin.jar

Also once we add this JAR file, we need to add following code snippet in whatever JSP file we need to add AJAX support.

<%@ taglib prefix="sx" uri="/struts-dojo-tags"%>

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sx" uri="/struts-dojo-tags"%>
<html>
<head>
<title>Welcome</title>
<sx:head />
</head>
<body>
<h2>Struts 2 Autocomplete (Drop down) Example!</h2>

Country:
<sx:autocompleter size="1" list="countries" name="country"></sx:autocompleter>
</action>
</body>
</html>

#################################################################################
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.


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.

No comments:

Post a Comment