Raw Servlet vs. Spring MVC [closed] Raw Servlet vs. Spring MVC [closed] spring spring

Raw Servlet vs. Spring MVC [closed]


If you're building a really quick and dirty demo that you have no intention of extending later, spring can result in a lot of additional configuration issues (not really if you've done it before, but I always end up fighting with it one way or another), so that might be a time to consider just using plain old servlets. Generally though, anything beyond just a super fast and dirty demo, using some form of MVC framework is going to make life in the future a lot easier and is also in line with best practices. Spring makes things super easy, just have to spend some time on the front end configuring everything.

I should note, there's nothing you can do with java servlets that you can't do with Spring. The big difference is setup time.

Edit: It's worth noting that when I posted this answer, I was unaware of Spring Boot that is actually quite easy to get up an running using either an embedded web server or a more conventional web container. Here's a link to a quick start example: http://projects.spring.io/spring-boot/#quick-start


Servlet technology is used for more generic server side extension for request-response paradigm.And Spring just uses it for the Web application over HTTP.

And some quote from here:http://www.reddit.com/r/java/comments/29f3ul/why_is_spring_mvc_better_than_servlets_jsp/

Servlets are based upon a low-level API for handling requests and responses. Web frameworks like Spring MVC are designed to make building web applications, which handle HTTP requests and responses, easier. Most Java web frameworks, including Spring MVC, use servlets behind the scenes.

You CAN use servlets to write a web application, but you'll have to handle all of the details manually. You'll get very little help with typical web stuff like validation, REST, request/response body for JSON, form binding, etc. You will end up writing lot of utility code to support your web application.

Web frameworks, on the other hand, are designed to make all of this stuff simple. With Spring MVC, you aren't bothered with manually handling the request and response even though you can still get access to them if you need to. Want to return JSON in Spring MVC? Just add a @ResponseBody annotation and Spring will append it. Want RESTful URLs? Easy. Input validation? Piece of cake. Want to bind form data to an object? Simple. With servlets, you'd have to do all of this stuff manually.

Using raw servlets can be a good learning experience though. It reallyhelps to clarify how web frameworks make life easy for you!


I have developed projects both with raw servlet and web app framework.Framework gives you everything, only you need to is to setup and config the env, coding is much more easier. The result is that you will know nothing about web dev.However, code with raw api and servlet gives you chance to gain experience and be a programmer.