• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

struts2 Vs spring mvc

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am using struts2 spring framework for my application.

i like to know how much the spring mvc will give advantage over struts2 because struts2 is having lot of development advantage so is it good thing to use spring mvc instead of struts2?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The two frameworks are very similar in many ways. The latest versions of Spring MVC are pretty nice.

Struts 2 integrates with Spring very well through the Spring plugin.

I don't know if there are any huge technical reasons to choose one over the other, quite frankly, but others may have more input.
 
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Spring Web MVC separates models and controllers clearer while Struts 2 mix Action and model. (I'm no Struts 2 expert, please correct me if I'm wrong).
2. Spring Web MVC has built-in support for many view technologies like JSP, Tiles, XSTL, Velocity/FreeMarker, PDF, Excel, JasperReports where as Struts has built-in support only for JSP, and Tiles.
3. Spring Web MVC offers more flexible view resolver.
4. Spring Web MVC offers more flexible handlers mapping.
5. Spring Web MVC offers more flexible model transfer.

I cannot think of why I'll use Struts, no, I never ever even think to use Struts after I was familiar with Spring Web MVC, and I believe everybody in this world will too (Don't take it too seriously).
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
KengKaj

Struts2 is not like Struts1. What you described is the comparison of Spring MVC to Struts1

Actually, Struts2 is a different product than Struts1, completely.

Mark
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark,
Struts 2 still mixes Action and model, I believe 1) is still true, as Struts 2 is like Struts 1+WebWork, but if I'm wrong, please explain or give a link.

But I'm not sure about 2)-5).
I'm not aware that Struts 2 has "built-in" support for many view technologies, and offers more flexible view resolver, handlers mapping, model transfer than Struts 1.
As I said, I'm no expert in Struts 2, I might be completely wrong about 2)-5). If you know that Struts 2 offers these features, could you please to explain more? Thanks.
 
G.Sathish kumar
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
kengkaj

Struts2 also giving support for JSP, Tiles, XSTL, Velocity/FreeMarker, PDF, Excel, JasperReports.

what i feel the difference between struts2 and spring mvc like spring have support like login mechanism and roll wise access on the view or model or resource.
we no need to use springutil to access the beans so instead we can call the bean by setter injection on controllers.
if any thing else please update me.
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

G.Sathish kumar wrote:
Struts2 also giving support for JSP, Tiles, XSTL, Velocity/FreeMarker, PDF, Excel, JasperReports.


Thanks for info, in that case Struts 2 and Spring Web MVC are equals in terms of View technologies support.

G.Sathish kumar wrote:
what i feel the difference between struts2 and spring mvc like spring have support like login mechanism and roll wise access on the view or model or resource.


Do you mean Spring Security? If you mean that, you can also use Spring Security with Struts 2 (or just plain-old servlets).

G.Sathish kumar wrote:
we no need to use springutil to access the beans so instead we can call the bean by setter injection on controllers.


You can use Spring Framework with Struts, so that is not an advantage of Spring Web MVC over Struts. We can DI anything to Struts Actions.

How about flexibility of view resolver and handler mappings? You can read detail of what Spring Web MVC supports on http://static.springsource.org/spring/docs/2.5.x/reference/mvc.html.
How about Validation in Struts 2? Spring Web MVC decouples Controllers and Validators, the Controllers just know Validator interface, not implementation. What is Struts 2 design about this?
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't forget the fact that Struts 2 mixes Action, model, and reference data. It's okay, if you can live with that.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
S2 offers the ModelDriven interface which puts a model object on the value stack; this is similar to Spring's model exposure, and lets the developer choose which way to do things.

S2's validation is handled via either XML, annotations, or manual validation (or any combination) and has a few mechanisms for determining how to handle validation flow.

Dispatching is handled with pluggable dispatchers (for example the Convention plugin provides configuration-free request mapping, overridable by annotation) with a few options available in the core.

Struts 2 is *nothing* like Struts 1; S2 *is* WW (with many enhancements at this point).
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for info, David.

Regarding, validation, for programmatically validation, WW couples Validation and Action.
http://today.java.net/pub/a/today/2006/01/19/webwork-validation.html

For Spring Web MVC, validation is completely decouple from Controllers, Controllers know only Validator interface, not implementation.
Spring Web MVC codes will be cleaner than WW codes for programmatically validations.
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
About about view resolver, as far as I see, Struts 2 couples action and view (like config action with .jsp).
http://struts.apache.org/2.1.2/docs/action-configuration.html

Spring Web MVC decouples Controllers and (concrete) Views completely.
Config for a controller only has reference to view name, but the actual view can be anything, locate in anywhere.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Struts 2 returns a string naming the view; how that view is resolved depends on either configuration, convention, annotation, or customized.

Validation is handled via either annotations or XML based on action names (and can include manual validation), action aliases, or a combination.
 
G.Sathish kumar
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Spring Web MVC decouples Controllers and (concrete) Views completely.
Spring decouples controller and validation
spring gives support on role wise access and login mechanism comparingly not available in the struts2
spring mvc have more support of the ioc comparingly not available in the struts2
spring mvc have type of controllers like please attachment


so i feel it is better to use spring mvc

please let me know if any more points there

Kengkaj Sathianpantarit

i got your point about spring security usefull in struts2 (today i read) thanks for your info
about view resolver i feel both struts2 and spring are same.

if any thing i missed please add

 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I see from the document, Struts 2 couples action with concrete view. Maybe there is another way. But as I said Spring Web MVC decouples them completely.

<action name="Logon" class="tutorial.Logon">
<result type="redirectAction">Menu</result>
<result name="input">/Logon.jsp</result>
</action>



And Struts 2 couples Action and model, Spring Web MVC decouples them, we just set command class to a Spring Controller.

Struts 2 uses Action properties as input properties


http://struts.apache.org/2.x/docs/comparing-struts-1-and-2.html
This doesn't make sense to me, why action properties are input properties? We input to action object? It's not reasonable.
Just for this single point, I would prefer Spring Web MVC rather than Struts 2, but it's just me.

IMO, Spring Web MVC reference documentation is better. You can read http://static.springsource.org/spring/docs/2.5.x/reference/mvc.html compare to http://struts.apache.org/2.x/docs/guides.html.
 
G.Sathish kumar
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kengkaj Sathianpantarit

Can i know why you hating to use action properties. it is advantage only write?

action properties means what i understand is the setter getter which is there in the action (controller) class to get the value automatically when on submit request.
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

G.Sathish kumar wrote:
Can i know why you hating to use action properties. it is advantage only write?

action properties means what i understand is the setter getter which is there in the action (controller) class to get the value automatically when on submit request.


It's only my preference. I think it doesn't make sense, actually what we want is we want input data to *an object*, like Customer object, we don't want to input data to Action (input to action for what!? why an action has firstName, lastName attributes!?).

Spring Web MVC does thing in a way that make more sense, domain object is not a part of Controller, but we specify command class to a Controller, and the Controller will create form backing object from the specified command class. For me that is a right design.

This is only my opinion and my preference, others don't need to agree with me.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I already stated: if you don't want to set properties on the action, use ModelDriven.

Not liking how something is done is one thing: actively denigrating something because you don't like it is something else entirely.
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it would be better if the framework enforces or encourages right design, and not allow doing strange thing.
It would be difficult if there are 10 devs in team, then I tell devs, don't use this feature, it's not good. There will be questions, why it's not good? If it's not good why the framework allows? I don't want to waste my time to answer these questions if I have another option that there is another framework that offers equal capabilities and enforces right design.
This applies to any framework in general, not just Web MVC frameworks.

Anyway as I said it's only my preference. The thing that I said is true that Struts 2 allows to put properties into actions which I think it's strange, and I don't like it. I don't think this is denigrating.

Struts 2 or even Struts 1 are decent frameworks, I don't mean it's unusable, if you read all of my opinions, you will see that I've already said, if we can live with this fact, it's all right.
Before correct or improve something, we have to accept it first, who know? Struts 3 might be much better than Spring Web MVC. Developers community will get benefits from competition.
 
G.Sathish kumar
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kengkaj Sathianpantarit wrote:I think it would be better if the framework enforces or encourages right design, and not allow doing strange thing.
It would be difficult if there are 10 devs in team, then I tell devs, don't use this feature, it's not good. There will be questions, why it's not good? If it's not good why the framework allows? I don't want to waste my time to answer these questions if I have another option that there is another framework that offers equal capabilities and enforces right design.
This applies to any framework in general, not just Web MVC frameworks.

Anyway as I said it's only my preference. The thing that I said is true that Struts 2 allows to put properties into actions which I think it's strange, and I don't like it. I don't think this is denigrating.

Struts 2 or even Struts 1 are decent frameworks, I don't mean it's unusable, if you read all of my opinions, you will see that I've already said, if we can live with this fact, it's all right.
Before correct or improve something, we have to accept it first, who know? Struts 3 might be much better than Spring Web MVC. Developers community will get benefits from competition.



what i feel about spring is great wrapper kind of frame work.

i dont think no frame work will give this much support like spring even if we think struts3.

no only web mvc but also about ejb scheduling jmx

can you please give your opinion about this https://coderanch.com/t/456968/Spring/spring-scopes
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Struts is *only* the web layer; it has no intention or desire of providing anything other than the web layer.
 
G.Sathish kumar
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:Struts is *only* the web layer; it has no intention or desire of providing anything other than the web layer.



it is correct but i meant was spring is provid lot of support for enterpraise techniques like ejb web service schedule mail so when i use spring web layer it is easy to integrate the various technique in the web layer context itself.

if i am wrong please correct me
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure, but it's just as, or nearly as, easy to use S2 actions. I just happen to prefer S2 on the web side, but I use Spring quite heavily (minus any EJB stuff, because I don't use EJBs).
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use Spring with S2 as well, don't worry.
 
G.Sathish kumar
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kengkaj Sathianpantarit wrote:

G.Sathish kumar wrote:
Struts2 also giving support for JSP, Tiles, XSTL, Velocity/FreeMarker, PDF, Excel, JasperReports.


Thanks for info, in that case Struts 2 and Spring Web MVC are equals in terms of View technologies support.

G.Sathish kumar wrote:
what i feel the difference between struts2 and spring mvc like spring have support like login mechanism and roll wise access on the view or model or resource.


Do you mean Spring Security? If you mean that, you can also use Spring Security with Struts 2 (or just plain-old servlets).

G.Sathish kumar wrote:
we no need to use springutil to access the beans so instead we can call the bean by setter injection on controllers.


You can use Spring Framework with Struts, so that is not an advantage of Spring Web MVC over Struts. We can DI anything to Struts Actions.

How about flexibility of view resolver and handler mappings? You can read detail of what Spring Web MVC supports on http://static.springsource.org/spring/docs/2.5.x/reference/mvc.html.
How about Validation in Struts 2? Spring Web MVC decouples Controllers and Validators, the Controllers just know Validator interface, not implementation. What is Struts 2 design about this?






you mean that docoupling between view controller model but it is looking same as like struts2 provide so can you please explain bit Elaborate because i looked the code in spring mvc so what i feel is

struts2
the contrller is declared in the struts config files so decoupling between view and contrller is fine and between model and contrller it looks like coupled

spring mvc
controller and view decoupled and model with contrller is also decoupled but when we use spring ioc dependency inject we can achive the model contrller dependency injection in struts2 also . it correct?
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

G.Sathish kumar wrote:
you mean that docoupling between view controller model but it is looking same as like struts2 provide so can you please explain bit Elaborate because i looked the code in spring mvc so what i feel is


It's not the same, coupling in config doesn't mean decoupling, it is just moving coupling to the other place.

Decoupling means controllers don't know concrete views even in configuration. You should read Spring Web MVC reference documentation.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for opening an old thread but I have some quite related questions. I am learning struts 2.1.8 and pondering over whether to use Spring MVC or Struts 2.1.8 for a web application. My specific question is - "Where does Struts 2.1.8 win from Spring MVC?" The answer could be something like "it has a jQuery Plugin, it has convention over configuration, it has good books and help material, etc." Curious to know all that could make Struts 2.1.8 win. If the list is not convincing, why would one choose Struts 2.1 over Spring MVC?

thanks,
Sanjay
 
G.Sathish kumar
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sanjay Kumar Patel wrote:Sorry for opening an old thread but I have some quite related questions. I am learning struts 2.1.8 and pondering over whether to use Spring MVC or Struts 2.1.8 for a web application. My specific question is - "Where does Struts 2.1.8 win from Spring MVC?" The answer could be something like "it has a jQuery Plugin, it has convention over configuration, it has good books and help material, etc." Curious to know all that could make Struts 2.1.8 win. If the list is not convincing, why would one choose Struts 2.1 over Spring MVC?

thanks,
Sanjay



Spring MVC have what ever the option available in struts2 even more.
i feel spring mvc is good to use because spring is integration framework so you can you dependency injection spring jdbc wrapper orm aop
as single framework help your all requirement instead struts2 is only mvc framework support.


 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sanjay Kumar Patel wrote:My specific question is - "Where does Struts 2.1.8 win from Spring MVC?" The answer could be something like "it has a jQuery Plugin, it has convention over configuration, it has good books and help material, etc." Curious to know all that could make Struts 2.1.8 win. If the list is not convincing, why would one choose Struts 2.1 over Spring MVC?


I have no experience in Struts 2. But about your last question, you have to ask people who study both Struts 2 and Spring Web MVC and choose Struts 2.

The fact that there are people use Struts 2 (or whatever web MVC framework) doesn't mean that they choose Struts 2 (or whatever) over Spring Web MVC. Somebody might even don't know what are differences, they might have been using Struts 2 just because their technical leader told them to use.

And don't forget that there are many Java web MVC frameworks, not only Struts 2 and Spring Web MVC.
 
Sanjay Kumar Patel
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

G.Sathish kumar wrote:

Spring MVC have what ever the option available in struts2 even more.
i feel spring mvc is good to use because spring is integration framework so you can you dependency injection spring jdbc wrapper orm aop
as single framework help your all requirement instead struts2 is only mvc framework support.



Doing some digging tells me that Struts 2.1.8 has a nice jQuery plugin (http://code.google.com/p/struts2-jquery/), whereas I could not see AJAX support in Spring MVC. Also, I do not know whether Spring MVC supports convention over configuration to the extent the convention plugin of Struts 2.1.8.

Comments?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I feel you're making unnecessary distinctions, really. I find both S2 and Spring MVC to be very capable, and when people ask which I'd choose I tell them it's more up to them, their team culture, etc. rather than any compelling technical benefits.

As far as the jQuery plugin goes, it's a very preliminary effort. One reason Dojo support was dropped in S2 was that it was too hard to maintain, and most people ended up writing plain old JavaScript anyway--a practice that will continue for all but the *most* trivial implementations. In my opinion it's best to write JavaScript in JavaScript: the code is more tightly-focused, domain-specific refactorings are easier, you can control when, where, and how the JavaScript is emitted and run, etc.

(That said, some of the stuff in Spring 3 looks really nice.)
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sanjay Kumar Patel wrote:
Doing some digging tells me that Struts 2.1.8 has a nice jQuery plugin (http://code.google.com/p/struts2-jquery/), whereas I could not see AJAX support in Spring MVC. Also, I do not know whether Spring MVC supports convention over configuration to the extent the convention plugin of Struts 2.1.8.

Comments?


Spring Web MVC supports CoC.
http://static.springsource.org/spring/docs/2.5.6/reference/mvc.html#mvc-coc

Regarding JavaScript, Spring JavaScript is an abstraction over Dojo (at least for now).
http://static.springsource.org/spring-webflow/docs/2.0.x/reference/html/ch11.html

Spring JavaScript doesn't tie to Spring Web MVC or Spring Web Flow, we can use Spring JavaScript in any environments.

Nevertheless, I don't like Spring JavaScript much because I don't like Dojo's documentation.
 
G.Sathish kumar
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kengkaj Sathianpantarit wrote:

Sanjay Kumar Patel wrote:
Doing some digging tells me that Struts 2.1.8 has a nice jQuery plugin (http://code.google.com/p/struts2-jquery/), whereas I could not see AJAX support in Spring MVC. Also, I do not know whether Spring MVC supports convention over configuration to the extent the convention plugin of Struts 2.1.8.

Comments?


Spring Web MVC supports CoC.
http://static.springsource.org/spring/docs/2.5.6/reference/mvc.html#mvc-coc

Regarding JavaScript, Spring JavaScript is an abstraction over Dojo (at least for now).
http://static.springsource.org/spring-webflow/docs/2.0.x/reference/html/ch11.html

Spring JavaScript doesn't tie to Spring Web MVC or Spring Web Flow, we can use Spring JavaScript in any environments.

Nevertheless, I don't like Spring JavaScript much because I don't like Dojo's documentation.




then i feel it is better to use spring because spring itself we complete all so why to use different framework and integrate it and for different framework integration there should be some extra memory expense also.
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Best Spring tutorial and examples.

http://www.javakeexample.com/2013/01/maven-spring-hello-world-example_16.html
 
I child proofed my house but they still get in. Distract them with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic