Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • 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

Difference between servlet and struts

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

What is the difference between servlet and struts ? Why we need struts?

regards,
Maheshwaran Devaraj
 
Ranch Hand
Posts: 471
Mac OS X Hibernate Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Maheshwaran ,

Well, they are two really very different things. Programming web applications using servlets only is a very hard thing, since you will have to write your HTML code inside the servlet, which will produce complex, unreadable and unmaintainable code.

The same thing is with JSP. If you program a web application using JSP alone, you'll have to put your java code in JSP pages, which will also be very hard to read and maintain.

This was the reason of the rise of the model 2 architecture, where the servlet controls the flow of the request, calls a model class to do the business logic, decides which view (jsp or other) to send to the user, and then sends the response to the user. This is known as the MVC (Model-View-Controller) design pattern.

Another pattern was also created and widely used, and that is the front controller pattern. This pattern simply says "Why do we have a separate controller for each request? Why don't we have a SINGLE controller to decide what should be done with the request?". So here we have a single servlet that takes ALL requests, and decides which class/method (model) should handle it, and which jsp/page/template (view) should be sent to the user.

Of course the classes that the servlet calls to handle the request should not always be the MODEL. A typical use of struts actions is just to validate the data, and configure it, then pass the data to a service layer class to do the business logic, and this makes those action classes be considered as controllers/controller extensions, rather than the model.

From the previous paragraph, I'm sure that you have already guessed that struts is a web framework based on the front controller design pattern, and this is correct. Using struts will simplify development a lot, since it separates the business logic from the flow control and the view.

Another thing is that struts provides a set of useful tag libraries, a validation framework and the tiles framework (which allows you to create complex layouts by gluing simple JSPs together).

I hope that this would help you.
 
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

Why we need struts?


We don't
We use web frameworks to make our life easier and to devote more time to our life as web frameworks are supposed to handle the common task we to do in each web application we work on (data validation, type conversation ...).
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Maheshwaran Devaraj:

What is the difference between servlet and struts ? Why we need struts?



As such they both are different. A Servlet is a technology and Struts is a framework which relies on or makes use of Servlets.

I believe Alaa Nassef's detailed reply will help you further!
 
Sheriff
Posts: 67745
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's like asking what the difference is between a brick and a house. The house is built with bricks.
 
Catch Ernie! Catch the egg! And catch this tiny ad too:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic