Spring, JSP and Servlet integration example

This tutorial shows an example on how to integrate Spring 3.x, JSP and Servlet 3.0. Though there are several MVC frameworks like JSF, Struts, Spring MVC etc. but still if you need to use Servlet without any MVC framework, here it is. Most of us know how to work with Servlet and JSP. So if you have any knowledge of Spring then it will be easier for you to pick up.

I have used here Servlet 3.x so that I can use annotation based URL mapping without configuring in the web.xml file. Spring also uses annotation based configuration and for that I have already configured in applicationContext.xml file. This is a basic example and youcan customize according to your needs. I have not used any database here for query instead I have used enum as a datasource. If you want you can use database and there are number of tutorials on Spring JDBC or Spring Hibernate.


Eclipse JEE Developer IDE
Tomcat 7.x
JDK 1.6
Jar files

integrate spring, jsp and servlet

We will first look into our deployment descriptor file – web.xml.


Now we will create a model class which has simply getters and setters for the attributes


We have then DAO but as I didn’t use database so I have used enum as a repository


Next Step is Spring Service class


Now we will create applicationContext.xml file and put it under WEB-INF directory


Now we will create servlet to see how Spring and Servlet get integrated. This servlet shows all the ToDo list in the jsp page.


Below servlet is used to get a ToDo for a given id


View page – index.jsp – where a ToDo for a given id and all the ToDo list will be shown


Now run the example and see the output.

Thanks for your reading. Please do not forget to leave a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.