Вы находитесь на странице: 1из 3

17/03/2013

Difference between Struts 1 and Struts 2 framework

Javarevisited
Blog about Java Program Tutorial Example How to, Unix Linux commands, Interview Questions, FIX Protocol, Tibco RV tutorials, Equities trading system, MySQL
Ads by Google

Struts

Java Tutorial

Java Test Tool

Java Web App

W EDNES DA Y , MA R C H 13, 2013

Searc h

Difference between Struts 1 and Struts 2 framework


Recent Posts
I had work previously on Struts 1 but never touched Struts 2,
specially since Spring MVC was there to take the leading role.

Top 15 Data Structures and Algorithm Interview


Questions for Java programmer - Answers

Recently one of my friend ask me to help with Struts2, which leads


me to look on Struts2 framework from start. First thing I wanted to

Difference between Struts 1 and Struts 2


framework

find out differences between Struts 1 and Struts 2 framework,


because in my experience, if you have worked in previous version

Bitwise and BitShift Operators in Java - AND, OR,


XOR, Signed Left and Right shift Operator
Examples

looking differences between two versions of Struts can quickly help


to find, what changes and What are the new features, concepts
and improvement is offered by Struts 2. Also difference b etween

Difference between Singleton Pattern vs Static


Class in Java

Struts 1 and Struts 2 is a good candidate to include in my list of


Struts interview question for quick revision. To my surprise, Struts 2

How to Increase Console Buffer Size in Eclipse


IDE - Output and Debug Console

seems to be completely different than Struts 1 framework, because


some of the most familiar stuff like ActionForm, struts-config.xml,
and Actionclasses are changed in Struts 2 framework. Struts 2
has also done good job on removing direct dependency of Action classes on Servlet API e.g. HttpServletRequestand

ReentrantLock Example in Java, Difference


between synchronized vs ReentrantLock

HttpServletResponse, which makes testing easy by using Dependency Injection concept. In this article, we will some
important differences between Struts 1 and Struts 2 framework.

Struts 1 vs Struts 2 - Differences


Here is my list of some common difference between Struts 1 and Struts 2 framework. This list contains some
observations, which can also help you to gauge some major changes in struts 2 from struts 1.

1) First major difference between Jakarta Struts 1 and Struts 2 framework is in Actionclass itself. In Struts 1 it's
mandatory to extend org.apache.struts.action.Actionand implement execute()method which returns
ActionForwardand accept HttpServletRequestand HttpServletResponse. This is not the case with Struts 2, here
Action class can be a simple POJO or Java object with execute()method. Also execute() method returns String rather
than returning ActionForwardobject. You can still use ActionSupportclass or Actioninterface but those are
completely optional.
2) Second main difference between Struts 1 and Struts 2 is on configuration files, earlier we used to configure Struts
using struts-config.xml,but with Struts 2 you can use multiple configuration file, most commonly used as
struts.xml. What is more important is declaration of Struts 2 Filter in web.xml e.g.

<filter>
<filter-name>struts2Fitler</filter-name>
RECOMMENDED FOR YOU
?
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2Fitler</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Also, if you notice, instead of mapping this to *.door *.actionwe have mapped it with *, which means all url pattern
will be flown to struts2 filter.
3) One more difference I noticed between Struts 1 and Struts 2 is on Front end Controller. In Struts 1, ActionServletis

Follow Us
Follow @javinpaul

1,803 follow ers

considered as FrontController while in Struts 2 its Filter, which can be considered as front end controller.
4) Another useful enhancement in Struts2 is Interceptor API, which allows to do lot of stuff much easily e.g. file upload

Javarevisited on

Follow

using Struts2's builtin FileUploadInterceptorclass.


5) One more difference between Struts 1 and Struts 2 which I like is removing dependency of Action classes to Servlet API

+2,500

in form of HttpServletRequestand HttpServletResponseclasses required in execute() method. Struts 2 don't


have such dependency and its execute() method doesn't required Servlet API.
There are lot more difference in Struts 1 and Struts 2 and I suggest going thorough Struts 2 documentation as you learn
Struts 2. To me, Struts 2 looks completely different than Struts 1. Since I am using Spring MVC more frequently, I still need
to explore Struts 2 more closely. I will keep this list of differences between Struts 1 and Struts 2 updated as and when I
found some more differences.

javarevisited.blogspot.in/2013/03/difference-between-struts-1-and-struts-2-mvc-framework-jakarta.html

1/3

17/03/2013

Difference between Struts 1 and Struts 2 framework

Other J2EE tutorials from Javarevisited Blog


How to configure LDAP authentication with Windows Active Directory using Spring Security
Difference between include directive and include action in Servlet JSP.
Difference between forward and send-redirect in Servlet
How to use JSTL foreach loop in JSP
How to control concurrent active user sessions in Java web application using Spring Security

Are you 40+


www.Varilux.co.in/Lenses
Varilux Brings Wide Range Of Progressive Spectacle Lens.Hurry!
Please share with your friends if like this article
Javarevisited
You might like:

Like

Bitwise and BitShift Operators in Java - AND, OR, XOR, Signed Left and Right shift Operator Examples
Difference between Singleton Pattern vs Static Class in Java
Javarevisited: FIX Protocol, tibco,unix and java tutorial with example
How to find duplicate records in a table on database - SQL tips

2,711 people like Javarevisited.

Recommended by
F acebook social plugin

Posted by Javin Paul at 5:46 AM

+5 Recommend this on Google

Labels: core java interview question, J2EE, jsp-servlet, struts

Subscribe by email:

2 comments:

By Javin Paul

Subscribe

Jitendra Gupta said...

Subscribe To This Blog Free

this is good article on Struts 2.0


Explore struts 2.0 architecture http://www.javaprogrammings.info/struts2.x.jsp

Posts
Comments

March 14, 2013 at 10:10 AM


Followers

Anonymous said...
Hi,
Can you write some article,
listing new component libraries, added on top of various MvcWebFrameworks
which is very easy/quick to use, and has many different object types.
My company is stucked with Struts1 and commonControls, and this is very hard to convince that bureaucracy...

Join this site


w ith Google Friend Connect

Members (936) More

one more thing.


is there any chance to change email, and send full page content, not just the first paragraph.
im very happy spending 10 minutes readying your posts, but this colourful page is a problem in openspace
March 15, 2013 at 10:03 AM
Already a member? Sign in

Post a Comment
Ads by Google

Enter your comment...

List Java
Java Application
Java Interface
Blog Archive
2013 (45)
March (9)

Comment as: Google Account


Publish

Top 15 Data Structures and Algorithm Interview


Que...

Preview

Difference between Struts 1 and Struts 2


framework...
Bitwise and BitShift Operators in Java - AND,
OR, ...
Newer Post

Home

Subscribe to: Post Comments (Atom)

Older Post

Difference between Singleton Pattern vs Static


Cla...
How to Increase Console Buffer Size in Eclipse
IDE...
ReentrantLock Example in Java, Difference
between ...
5 books to learn Spring framework and Spring
MVC f...
How to create Immutable Class and Object in

javarevisited.blogspot.in/2013/03/difference-between-struts-1-and-struts-2-mvc-framework-jakarta.html

2/3

17/03/2013

Difference between Struts 1 and Struts 2 framework


Java -...
How to write Unit Test in Java using JUnit4 in
Ecl...
February (18)
January (18)
2012 (218)
2011 (145)
2010 (33)

References
Java API documentation JDK 6
Spring framework doc
Struts
ANT
Maven
JDK 7 API
MySQL
Linux
Eclipse
Copyright by Javin Paul 2012. Powered by Blogger.

About Me

Privacy Policy

javarevisited.blogspot.in/2013/03/difference-between-struts-1-and-struts-2-mvc-framework-jakarta.html

3/3

Вам также может понравиться