Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I convert my application in servlet to Spring using REST web service and spring boot?

I have done my Dynamic web project using Servlet 3.0.

Can I convert this project to Spring project by some kind of web service (REST calls) and Spring Boot.

Or Is there any other possible ways to do that.?

Note: My project includes servlet controller class (GET and POST) , web content like jsp, ajax, javascript, css, html, etc

like image 549
Mebin Joe Avatar asked Jan 27 '16 06:01

Mebin Joe


1 Answers

You can try doing this, if you are using annotations:

  1. Convert your servlet classes to spring controller classes.

Mark class as @Controller and remove extends part of class, in your doGet and doPost add annotation @Requestmapping(value="/someURL" method="RequestMethod.GET" and @Requestmapping(value="/someURL" method="RequestMethod.Post"

  1. In the above methods return the name of jsp file, where you want to forward your processed data.

  2. You will have access to Model object in the above controller classes and jsp in order to process data.

  3. In your web.xml define DispatcherServlet and a configLocation to scan controllers.

Essentially what you are doing is to introduce Spring just defining DispatcherServlet and then the spring controller classes are loaded.When you hit a URL it will be routed to correct controller.

Good Luck.

like image 175
abdulrafique Avatar answered Oct 27 '22 09:10

abdulrafique