aspose file tools*
The moose likes JSP and the fly likes difference between struts and jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "difference between struts and jsp" Watch "difference between struts and jsp" New topic
Author

difference between struts and jsp

Anandh Ramesh
Ranch Hand

Joined: Dec 15, 2004
Posts: 61
hi

can anyone please tell me what is hte diference etween jsp and java struts? which is more beneficial? how will the complexity of a system using jsp change if it is transferred to struts?

any help is appreciated.

-Anandh


cheers,<br />Anandh
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
struts is a framework and jsp is a web tier technology. we use struts to speed up our web application development. Moreover struts give us easy, flexible, nice and clear architecture.

for more, some reading is required. there is no other better substitute.
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
There is no or-or...
Struts itself makes extensive use of JSPs...

As to whether to use Struts: the answer to that is NO.
It's an overly complex, bloated, tech. It's the EJB of web application development.
You're far better off using a lightweight framework like Spring or rolling your own mini-framework.


42
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Jeroen,
I haven't heard this before. You are the only one saying this to me.

Anybody else wanna say something about struts framework. I really need to hear something, like pros and cons, from a third party , after getting Jeroen comments.
Damanjit Kaur
Ranch Hand

Joined: Oct 18, 2004
Posts: 346
Hi,

I would prefer struts in case of a big application but for smaller one JSP seems better.
Damanjit Kaur
Ranch Hand

Joined: Oct 18, 2004
Posts: 346
how will the complexity of a system using jsp change if it is transferred to struts?

The complexity is solved mainly thru the use of validation framework in struts where you can specify all common validation in one file and use that in any jsp form with struts code,thereby reducing the html code and also java script/jsp code for validations in each html/jsp file and making the jsp file look simpler and more readable.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Damanjit Kaur:
Hi,

I would prefer struts in case of a big application but for smaller one JSP seems better.


Damanjit,
what does it mean? you are not going to use jsp in big applications.

Note: There is no comparison b/w JSP and struts. JSP is a web tier technology, and the struts is the framework.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Damanjit Kaur:
The complexity is solved mainly thru the use of validation framework in struts where you can specify all common validation in one file and use that in any jsp form with struts code,thereby reducing the html code and also java script/jsp code for validations in each html/jsp file and making the jsp file look simpler and more readable.


I think javascript is still required for client-side validation.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Struts is a framework that handles a lot of the MVC pattern for you.
It's build using Servlets, Beans, JSPs, and Custom JSP Tags.
Many things, like validation, file uploading, and the MVC structure are already incorporated into Struts.

If you're going to write a fairly large web app using the MVC pattern you can probably save yourself a lot of time by using it as a lot of the grunt work has been done for you. For smaller, simpler apps, it may make sense to either use a lighter framework or to roll your own solution.

Often these small projects grow into larger ones and the developer, in hind site, realizes that he/she has written a lot of same code that exists in one of these frameworks (re-invented the wheel).

As the earlier poster said, there is no either or. One is build on the other.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Scott Duncan
Ranch Hand

Joined: Nov 01, 2002
Posts: 363
I will give you that stuts is a bit bloated. It baffles me a bit the number of people that say struts is overly-complex. I think struts is pretty simplistic. All it takes is understanding and to gain understanding you actually have to experience using it. Struts, in conjunction with Tiles, can speed up development time dramatically. Once the application is set up, you just build a template and the rest is just content. Struts handles validation, repopulation of forms, navigation/control, etc. I do not miss the days of mapping request parameters to JavaBeans.

I cannot speak for Spring as I have never used it but I understand it is very impressive. I actually prefer Java Server Faces but that is just me.

BTW, client side validation can be handled with the validator api....


No more rhymes! I mean it!<br /> <br />Does anybody want a peanut?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

I haven't heard this before. You are the only one saying this to me.


Count me in as not a big fan of Struts. Love the idea, but am not impressed with the implementation of that idea.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Scott Duncan
Ranch Hand

Joined: Nov 01, 2002
Posts: 363
Bear,

What do you think of JSF?
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Bear Bibeault:
Count me in as not a big fan of Struts. Love the idea, but am not impressed with the implementation of that idea.


Bear,
You are really a big entry.
I haven't tried any other framework. So, now I'll try Spring then say something about Struts.

Jeroen,
Thanks for your comments.
Anandh Ramesh
Ranch Hand

Joined: Dec 15, 2004
Posts: 61
can anyone suggest me a good study material for struts? i need something online please...

cheers
-Anandh
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
here is a free book
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Hey Folks,
Would like to share Struts Live Chapter: Nested POJOs

About the Chapter

The new chapter will include a solution to one of the most frequently heard complaints about Struts: that it doesn't provide a simple way to meaningfully nest POJO graphs in ActionForms. The provided example code solves this problem and includes an integrated solution for automating conversion, formatting, and validation.
Damanjit Kaur
Ranch Hand

Joined: Oct 18, 2004
Posts: 346
Hi Adeel

Why I would prefer to use Struts in big application and not in smaller one is much better explained by Ben.

and for client side validation java-script is required, but with struts validation framework, we don't have to write those java script functions for validations in each jsp file. I mean to say that it reduces coding.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Damanjit,
yeah now I got you. But when you said i prefer jsp for small apps. It sounds to me that you are not going to use jsp in big apps.

wasn't it better to say, "I prefer to use some other lightweight framework or something of my own rather than struts". Anyways your words confused me a bit, now I understood what you meant, sorry.

And I think even without using struts validation mechanism we can write all our js validation functions in one javascript file.

cheers.
[ December 29, 2004: Message edited by: Adeel Ansari ]
David Sappia
Greenhorn

Joined: Dec 29, 2004
Posts: 7
Hi!
Validation in Struts is made mainly with a xml file. That's really nice, and you can even define different files for different languages. The validations you specify (for example in JavaScript if you want to make validation in the client side) in that file can be used in different JSPs, but are stored in a single file!
It's like the flow control, its specified in a single xml file, struts-config...
I like Struts!! :-)
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by David Sappia:
Validation in Struts is made mainly with a xml file. That's really nice, and you can even define different files for different languages. The validations you specify (for example in JavaScript if you want to make validation in the client side) in that file can be used in different JSPs, but are stored in a single file!
It's like the flow control, its specified in a single xml file, struts-config...


David Sappia, Welcome to the Javaranch!
I think you are talking about server-side validation.
[ December 29, 2004: Message edited by: Adeel Ansari ]
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
Originally posted by Adeel Ansari:


I think you are talking about server-side validation.


he is. I see a common problem with (mainly I hope starting) developers in that they more often than not don't know the difference between clientside and serverside processes.

This leads to the constant stream of questions from frustrated people that can't get their Javascript to incorporate JSP fragments to be executed when the JS is called, people thinking (in contrast) that Javascript in JSPs is executed on the server, etc. etc.

As to Struts being heavy: it is. You often need several times more code to do something in Struts than using a lightweight approach.
Also the overreliance on XML files makes for lack of testability of code before deployment.
David Sappia
Greenhorn

Joined: Dec 29, 2004
Posts: 7
Hi again!
Now Im a little confused. In fact I havent used a lot the Validator so I think Im probably confusing things: that JavaScript code that is in validator-rules.xml is for being inserted in JSPs pages, and therefore for client side validation, isnt it? That was what I thought, now I am not sure!
Thank you in advance! :-)
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Yeah Jeroen, now I am seeing your way that why you dont vote for struts.
thanks.
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
Originally posted by David Sappia:
Hi again!
Now Im a little confused. In fact I havent used a lot the Validator so I think Im probably confusing things: that JavaScript code that is in validator-rules.xml is for being inserted in JSPs pages, and therefore for client side validation, isnt it? That was what I thought, now I am not sure!
Thank you in advance! :-)


if that's what's happening it makes Struts even worse...
XML should NEVER contain code that is later put into something else. XML should be configuration data and persistent storage, but not code.
David Sappia
Greenhorn

Joined: Dec 29, 2004
Posts: 7
Hi!

Well, do you think that's a big drawback of Struts? You have that xml file with the client side validation javascript, you reuse this code, you have it stored very tidy... What's the problem? If the code was stored in a *.whatever file, it wouldn�t be better I suppose :-)

Of course as I haven't used the Validator very much, maybe there are a lot of things you can't do with it, but maybe not... And so far it seems very nice!!
Damanjit Kaur
Ranch Hand

Joined: Oct 18, 2004
Posts: 346
Hi,

Well, actually I thought David was not confused about what he was saying about client side validation. Because client side or server side validation can be done by same xml validation file. though for client side validation one has to specify the tag something like this
for form tag:
<html:form action="/AddressJavascriptValidation" method="post" onsubmit="return validateAddressForm(this);">
....
....

<html:javascript formName="AddressForm"/>
<html:form/>

and for server side validation :
WE just write :
<html:form action="/AddressJavascriptValidation">
and require no tag for
<html:javascript formName="AddressForm"/>

I know in client side validation java script code is run on client machine rather than form data being sent to server and there validation being formed as in case of server side validation.


XML should be configuration data and persistent storage, but not code.


I think in struts validation framework also, xml is being treated as configuration data though with the use of some static code which can be substituted in any jsp file to change their behaviour. I think the xml files are a bit like properties file though with more flexibility unlike properties file. The purpose of both is to change the run time behaviour of some application according to values that we provide in these files. And its easy to change the values in one file rather than in many files.


And I think even without using struts validation mechanism we can write all our js validation functions in one javascript file.


I agree with you Adeel for one javascript file which can solve the same purpose with even less code thatn whole struts validation framework code. But I think here the purpose might be to improve the readability of jsp by making its code simpler than it would have been with one javascript file. Because there also though you make each jsp simpler but still the calling javascript functions make each tag a bit more complex than struts tag.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Damanjit,

I think you are also calling the javascript function in the example above,
onSubmit="validateAddressForm()", something like this. anyways.

I think now it depends upon the ones perception. I dont say struts is overly complex but i must say that struts is a heavyweight framework and do overreliance on XML. And I think it results in performance lack, may be neglegible.

And it doesn't give us a nice mechanism to handle POJOs, as discussed in previously given link. Although, dont know any framework which is better in dealing with POJOs. Haven't tried Spring yet.


cheers.
[ December 31, 2004: Message edited by: Adeel Ansari ]
Joseph Hatton
Greenhorn

Joined: Dec 12, 2002
Posts: 20
Hi, all.

I am very sadden by some of the comments made about Struts. I don't understand what is meant by bloated and complex. If you mean "bloated" by the size, the total size of Struts1.1 of the TLDs, JARs, and XMLs is approximately 1.4 meg which is rather small size. If you mean "bloated" by the amount of functionality, I am pretty impressed by the amount of functionality packed in Struts1.1. It has client and server validation, built-in error handling, templating, JSP custom tags, and internationalization. I would like to see other frameworks that have these functionality and still be considered "lightweight". If you mean "bloated" in terms of performance, we have mission critical Struts applications running on 5 different servers(Tomcat,WebSphere, WebLogic,JRun,JBoss) and its performance and response time are great!

There has been a growing trend to use Struts. Struts has provided solid foundation for building small, medium, and large applications. Mastercard, Monsanto, IBM, Express Scripts, Anheiser-Busch,Citicorp and etc. etc. Temendous amount of companies that has implemented Struts speaks for itself. A good example is IBM's implementation of Struts in their WebSphere 5.0 admin tool for deploying web apps and server configurations.

Whether it is a small, medium or large app, the biggest and strongest advantage of Struts is it MVC pattern! In web application, there has been a evolutionary movement from Model I to Model II type design. Strut's framework is to separate the business logic from the presentation logic. Of course, if you have 2 static pages you would not want to use Struts. Or you can build your own framwork. However, the amount of time it takes to create the data access layer, error handling and business layer, it would be about the same amount of using Struts. Also, Struts is a framework. It is exactly that...a framework. It is not suppose to provide every functionality like POJO graphs. It suppose to provide basic web mechanics like session management,handling request/response and fowarding, so you can concentrate on the business aspect of the application.


If you think Struts is complex, you haven't seen JSF(Java Server Faces). The learning curve of JSF is higher than Struts. JSF framework concept is totally different than Struts in that the components are tied directly the the form and higher abstactions like actionListener, dataTables, changeListeners, action,

So please if you make a blanket generalization, I would appreciate that you clarify and state your reasoning behind your claim. I expect statements like that from green horns like me.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

Originally posted by Joseph Hatton:
If you think Struts is complex, you haven't seen JSF(Java Server Faces). The learning curve of JSF is higher than Struts. JSF framework concept is totally different than Struts in that the components are tied directly the the form and higher abstactions like actionListener, dataTables, changeListeners, action,

So please if you make a blanket generalization, I would appreciate that you clarify and state your reasoning behind your claim. I expect statements like that from green horns like me.


Talking about blanket generalizations....

JSF concepts are totally different than Struts. That's the point. It is a component oriented framework. Struts is not. I've used both Struts and JSF and I found JSF a lot easier to get a quick handle on. It's not perfect and is still too new and lacking some basic functionallity.

I would say most of Struts popularity is do to it's maturity. It's been around quite a bit longer than most. So it's natural that Struts would be the front runner in web app frameworks. It's also natural that more vendors support Struts than any other framework for the very same reason. That doesn't make it the best. Just the most widely used. It's something that every java web developer should probably be familiar with.

If I had to choose a framework right now for a new web application, I would probably go with Tapestry. Here are some brief opinions on some of the others.

WebWork - might as well use struts
Spring - Trying to solve to many different problems and handle too many different domains
JSF - Too new.

I am in the middle of a project at work right now and I am really considering switching to Tapestry. I'm using JSF right now but I am running into so many roadblocks that I have found simple solutions for in Tapestry. But it would really set me back to have to change so much code over. Ugh! I don't know what to do. Luckily my job doens't depend on this project.


GenRocket - A Test Data Generation Platform
Damanjit Kaur
Ranch Hand

Joined: Oct 18, 2004
Posts: 346
Hi Guys

Happy New Year!! May Spring,JSF,Struts,Tapestry ..... framework get easier, less complex, lightweight etc. etc. in New Year!!

Joseph Hatton
Greenhorn

Joined: Dec 12, 2002
Posts: 20
Thanks, Gregg.

I am not familiar with Tapestry, but I heard good things about it. I will have to look into it.

Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
Struts tries to do too much.
It also does way too much through obscure XML files and custom libraries which cannot be easily omitted or replaced by something else (their custom tag lib for example which is an almost one for one replication of JSTL).

It takes several times the code to do something in Struts from what you would need doing things some other way which is also MVC (Struts neither invented MVC nor is MVC limited to Struts, I've written my own MVC framework which is just a few hundred lines of code).

My opinion is based on using Struts and working through several tutorials and books, none of which could convince me that Struts is in any way preferable to the way we're working already. In fact, it convinced me that going with Struts would increase our workload for no gain at all except that nice warm feeling of using open source instead of our own implementation...
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
and for those that didn't realise: that last was sarcasm
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

Jeroen makes some really good points. Personally, I don't think Struts brings much to the table that can't be done in a better, leaner, and more straight-forward fashion with a handful of custom code and custom tags (and fewer of those since the advent of the JSTL).

Like Jeroen, I have implemented a light-weight Model 2 framework that does everything I need it to do with minimal overhead and complexity. All it takes is a good understanding of how Servlets work and what Model 2 is all about -- knowledge which anyone working in a web app environment should have under their belt.

Jeroen's point about some people feeling that MVC is not possible without using an established framework is a good one. And the irony is, relying on such a framework can sometimes actually hide so much of the details that gaining basic knowledge about "How Web Apps Work" is delayed or prevented.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

The only advantage Struts has I think over a custom framework (and I'm very certainly no Struts fan) is it is a well understood, well documented framework. So the only real benefit I see it having over a custom design is the learning curve for a new developer (who is familiar with Struts) is smaller.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Scott Duncan
Ranch Hand

Joined: Nov 01, 2002
Posts: 363
I've used both Struts and JSF and I found JSF a lot easier to get a quick handle on.


I agree with this. I have found that JSF was fairly easy to learn.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

Originally posted by Jeroen Wenting:
Struts tries to do too much.
It also does way too much through obscure XML files and custom libraries which cannot be easily omitted or replaced by something else (their custom tag lib for example which is an almost one for one replication of JSTL).


The Struts tag libraries existed before JSTL so to be fair, Struts didn't really replicate anything; JSTL simply made many of the logic and bean tags redundant. Struts documentation clearly states that you should prefer JSTL over any Struts-specific tags.

As for trying to do too much, well, bloating is natural in the lifecycle of any framework that has as much usage as Struts. It's up to the developers to pick and choose what features they want and how they use them. Developers can make their use of a framework as complex or as simple as they want (or can). In my experience, a lot of the complexity you see in code is really due to a developer's inexperience or poor design choice. I recently refactored some really awful code/JSPs to about 1/4 its original length, making it much cleaner/straightforward/readable/maintainable. Both before and after implementations used Struts.

As for home-grown vs. out-of-the-box framework, I go by the 80-20 rule. If there's already something out there that can provide 80% of the functionality I need, I'll take it. And for large projects involving more than 2 or 3 developers, I'd rather have code that's already been proven and tested. I'm on the project to write business solutions, not frameworks. Any time spent writing code for a custom framework takes away from the time I spend on the actual work I've been brought on to do. IMHO, having to custom-code only 20% is well worth having to live with the constraints that the framework imposes.

I do not regret having used Struts in the past and I have learned a lot by using it. Having said that, however, I have worked with Struts for quite a while and have grown a bit disenchanted with it.

So, to the original poster: take whatever has been said about Struts in this thread with a grain of salt. If you have the luxury, take the time to evaluate the framework for yourself and compare it with other options such as JSF, Spring, Tapestry, etc. Take a good look at your development team's skills set and see which framework fits best with those skills. Above all, don't be too quick to blame the framework. As with any tool, frameworks have to be used in the right way and circumstance. Ultimately, it's the developer, not that framework, that makes or breaks the application and he has to take responsibility for the choices he makes.

My $0.02


Junilu - [How to Ask Questions] [How to Answer Questions]
Joseph Hatton
Greenhorn

Joined: Dec 12, 2002
Posts: 20
Hi, All.

I think development is dependent on the project. I think some of people tend to take what they know and design around it. One project, I developed my own framework and other project, I decided to use Struts. In my current project, I am using JSF. AND in another project, the client piece was written in .NET but the backend was J2EE.

And just because something is popular or mature doesn't mean that people will use it just because of the trend or for the sake of popularity. I used Struts long time ago when it wasn't even popular and the name was barely used!

I guess it depends on what you know and what the requirements demand.
Erwin Bredford
Ranch Hand

Joined: Feb 11, 2003
Posts: 167
i want to know if the struts framework provides skins .


--One learns a lot during a lesson but seeing is not enough,you must do;knowing is not enough ,you must apply--<br />SCJP 1.4,SCBCD,SCEA part 1,OCM JEE Enterprise Architect.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by chinedu efoagui:
i want to know if the struts framework provides skins .


i suggest better make a new thread for it.
thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: difference between struts and jsp
 
Similar Threads
Struts e JSP
Interview with JP Morgan Chase - Java
please help in struts -web-inf/web.xml not found
please help in struts -web-inf/web.xml not found
Need help in JSP