From the Servlets/JSP to Struts, JSF and Spring @MVC: how did we get there?
(presentation from Nik Trevallyn Jones and Michael Isvy at the SingaSUG (Singapore Spring User Group).
connection: please answer this survey: http://tinyurl.com/singasug Nik TJ and Michael I : web frameworks in Java Salah C. and Srikanth N : Spring MVC live coding session N
Consulting on Spring since 2008 Has Taught Spring to more than 1000 students in 6 years OpenSource Contributor to several Spring projects – Spring HATEAOS, Spring ROO… M
Java EE specification Technically JSF is not exactly a web framework but rather a specification and an implementation – We’ve used the word “framework” here to keep things simple N
" public void doGet(HttpServletRequest req, HttpServletResponse resp) {" …" } public void doPost(HttpServletRequest req, HttpServletResponse resp) {" … } " } Not a POJO Request params parsed manually Form validation done manually No I18N support … Verbose XML config M
some major limitations – Form validation very limited – Couldn’t disable JavaScript – No support for “GET” methods… Specification versus framework – For it to succeed, JSF should have been a framework, not a specification ▪ Frameworks can be updated every month ▪ Java EE Specs are updated once every 2 years M
similar to Struts – But more modern ▪ Easier to extend ▪ Well integrated for Dependency Injection public class UserController extends SimpleFormController { private UserService service; public ModelAndView onSubmit(Object command) { //... } } N Not a POJO Request params parsed manually Form validation done manually Simpler XML config … No Internationalization support
go for Spring @MVC! public class UserController extends SimpleFormController { private UserService service; public ModelAndView onSubmit(Object command) { //... } } @Controller public class UserController { @Autowired private UserService service; @RequestMapping(value="/users/", method=RequestMethod.POST) public ModelAndView createUser(User user) { //... } } N Now POJO based!! No XML needed for controllers anymore!!
is neat and elegant on the controller side – Form submission, Validation, File upload, testing… Spring @MVC is view-agnostic – No much tooling for integration with CSS/JavaScript frameworks – It’s your job to create the custom tags you need ▪ But that’s not hard! N
contains custom tags <html xmlns:custom="urn:jsptagdir:/WEB-INF/tags/html" …> … <custom:inputField name="firstName" label="Enter your first name" /> <custom:inputField name=”lastName" label="Enter your last name" /> </html> JSP file 1 line of code instead of 9!! N
unified around Struts! JavaScript and CSS: you now have good frameworks! Spring @MVC now is the most popular Web framework for Java Create your own custom tags for the View layer Use Dandelion for your DataTables N