• 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

Benefits of Using Spring and Struts

 
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.
I have a question about Using Spring and Struts.
The benefit of integerating Spring with Struts -as I understood it- is, if my Actions use Hibernate (for example),
I can inject Spring Hibernate templates into my actions.
And my Actions will have accessor methods to set my Hibernate Dao.
Right ?
(Well, the same question for using Spring and Tapestry).
Thanks folks.
 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by John Todd:
Hi.
I have a question about Using Spring and Struts.
The benefit of integerating Spring with Struts -as I understood it- is, if my Actions use Hibernate (for example),
I can inject Spring Hibernate templates into my actions.
And my Actions will have accessor methods to set my Hibernate Dao.
Right ?
(Well, the same question for using Spring and Tapestry).
Thanks folks.



No, that's exactly what you should not do. Your Actions should not be the service layer, because then it's impossible to use them without Struts.

The proper idiom is to have separate service and persistence layers, without any thought to the web or UI layers. The service will use the DAOs and model objects to accomplish tasks. You can then use them with Struts or Tapestry or Spring MVC or anything else you choose for the front end. You can also expose the services as Web services.

Just don't put that stuff in the Actions. That's a dead end.
 
Hussein Baghdadi
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you know any online examples of using Spring and Struts ?
Thanks.
 
Michael Duffy
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by John Todd:
Do you know any online examples of using Spring and Struts ?
Thanks.



Google can find plenty. The Spring docs have examples, too:

http://www.devx.com/Java/Article/29208
http://www.springframework.org/docs/reference/webintegration.html#struts
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The clearest benefit of integration IMHO is that you can get to springified beans easily from the Action layer.
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm curious about Spring-tapestry integration. In struts its probably not a big deal to pull action classes out of a spring context by overriding the method that creates the action classes.
How does it work in tapestry. Are tapestry pages configured within Spring?
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Karthik Guru:
I'm curious about Spring-tapestry integration. In struts its probably not a big deal to pull action classes out of a spring context by overriding the method that creates the action classes.
How does it work in tapestry. Are tapestry pages configured within Spring?



No. I'd go into more detail but you've somewhat highjacked this thread. If you want to know more about Spring-Tapestry integration, start a new thread.
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am currently working on a project wherein i am integrating struts with Spring. Why people normally integrate spring with struts is because most of the web applications are designed and developed using Struts. But struts is basically a VIEW and Controller framework and doesnt offer too much on the JDBC part. Integrating spring with Struts offers you Spring JDBC which takes care of exception handling, avoiding the try, catch, finally blocks which make your jdbc code look very complex than it actually is. Also Spring provides you great classes which map a row of the DB with a user defined object and return a List to give just one example. So if you are looking for a framework which takes care of the MVC then you may look into the option of integrating Struts and Spring. Struts handles the V and C part and Spring takes care of the M
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Struts handles the V and C part and Spring takes care of the M



What about Spring MVC ? Nobody mentions it.
I don't see the need to use Struts.
 
dnyan ginde
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes you are absolutely right. There is no need to use Struts at all. But the problem is that developers and architects over the world are comfortable using Struts and Struts as such has become a standard for developing web applications. But there are quite a few exciting features offered by Struts because of which people tend to use Struts. Its more a matter of being comfortable with using a framework.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Struts as such has become a standard for developing web applications.


I would not call Struts a standard I consider it an option, more than a standard, especially when using Spring.
 
dnyan ginde
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, when i said Struts is a standard i meant that developers around the world are comfortable using Struts to develop web applications. Spring is new and will take time to catch up and be as popular as Struts.
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by dnyan ginde:
Hello,
...
Integrating spring with Struts offers you Spring JDBC which takes care of exception handling, avoiding the try, catch, finally blocks which make your jdbc code look very complex than it actually is. ...M



I do not think a new framework should be introduced to get avoid try-catch-finally block. What is real substance of Spring JDBC?
 
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I do not think a new framework should be introduced to get avoid try-catch-finally block.



Simply avoiding a try-catch-finally block is not a reason to consider using Spring JDBC. One valid reason to use Spring JDBC is to avoid the resource leakage that comes with incorrect coding of the try-catch-finally blocks and nested try-catch-finally blocks that are necessary to do it correctly or the inevitable cut-and-paste errors of even correct code. Spring uses the Template design pattern to control the workflow of using JDBC making sure to correctly clean up the resources used so you can concentrate onwriting code that actually does something of value in your app. Typically you just have to implement a call back method that does the important work. You also get to use Spring's exception hierarchy that takes care of decoding database specific error codes for you marshalling them into sensible RunTime exceptions that you can catch at the most apprpriate layer in your system. This helps if you need to change the database or your data access strategy even allowing you to mix strategies, i. e. JDBC and Hibernate if you like.

JDBC is just a tiny part of what Spring has to offer to simplify your app development in every layer of your app. In my experience I can't think of a single good reason to not use Spring for any non-trivial app.
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does that all mean, that we can avoid port number :8080 in the URLs while using struts ?

Or what is the other way to do that ?
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by dnyan ginde:
Hello,

I am currently working on a project wherein i am integrating struts with Spring. Why people normally integrate spring with struts is because most of the web applications are designed and developed using Struts. But struts is basically a VIEW and Controller framework and doesnt offer too much on the JDBC part. Integrating spring with Struts offers you Spring JDBC which takes care of exception handling, avoiding the try, catch, finally blocks which make your jdbc code look very complex than it actually is. Also Spring provides you great classes which map a row of the DB with a user defined object and return a List to give just one example. So if you are looking for a framework which takes care of the MVC then you may look into the option of integrating Struts and Spring. Struts handles the V and C part and Spring takes care of the M



This is the most terrible explanation for using Spring with Struts. Why do you want to bring in JDBC/Data layer into the Presentation layer?

The benenfit for using Spring in Struts is to get Service classes/beans which will get injected by the framework. This provides a clean separation of presentation logic and business logic as Actions classes will no longer depend upon concrete Service classes.

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

Originally posted by varun bihani:
Does that all mean, that we can avoid port number :8080 in the URLs while using struts ?

Or what is the other way to do that ?



Not sure what you are talking about. Port 8080 is typically used by tomcat servers.

Struts, like any other generic MVC frameworks, uses urls as the resource location mechanism, unlike newer component based presentation frameworks like JSF. Spring does not save you from this.
[ November 23, 2006: Message edited by: Jeevan Philip ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic