File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes why to use struts2.x Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "why to use struts2.x" Watch "why to use struts2.x" New topic

why to use struts2.x

Nishita Jain
Ranch Hand

Joined: Mar 30, 2006
Posts: 97
Hi ,
I want to know that why should we use struts 2.x over struts1.x
I know what is the difference between these two but from that i couldn't found why we should use struts2.x
I felt that 2.x is bit hard to understand and interceptor concerns are very high in it.I feel it is more complex.

So pl help me out

Joe Ess

Joined: Oct 29, 2001
Posts: 9189

I have used Struts since it came out and recently picked up Struts 2. I think Struts 1 is easier to pick up, but it is less flexible. One ends up writing a lot of code to wedge business logic into the framework.
Struts 2 has a bit more of a learning curve, but it has more features. Unfortunately, because it's very flexible it is also hard to get a grasp as to where to start.
One big advantage for Struts 2 is that you don't have to override or implement an Action class. Just use a POJO. Less coding for the framework means you can be more productive on your app.
Struts 2 does away with the ActionForm so you can use the same data beans in your front end and your business logic. Again, less coding for the framework.
Interceptors aren't that big of a deal and they're really useful. Do you want session information in your action? Implement SessionAware. The session interceptor detects that interface and sets the session on your action. Need the servlet response, implement ServletResponseAware. Easy!
Interceptors are also useful to take care of the repetitive set-up code you write for several actions. I made a Hibernate interceptor to handle setting up all my data processing actions.
Don't like interceptors? You don't have to use them. One can get the session and response from the various context objects. I could have just as easily made a Hibernate base class and derive all my data processing actions from it. Again, the framework is really flexible.
I put all the links that helped me learn Struts 2 on our Struts FAQ Page.

[How To Ask Questions On JavaRanch]
Tejas Jain
Ranch Hand

Joined: Mar 04, 2008
Posts: 119
I think the biggest advantage of struts 2 over struts 1.x is that struts 2
supports RIA client (AJAX) much better through using DOJO.

There are a lots of architecture changes between struts 2 and 1, but not everyone likes the changes. In general, I do not like a framework that makes
a simple task harder.

"Knowing is not enough, you must apply... Willing is not enough, you must do."
--Bruce Lee
I agree. Here's the link:
subject: why to use struts2.x
It's not a secret anymore!