How can i create fast and easily a web application using java (and MVC)

Using Servlets directly in an application server is not flexible enough and too much code and too complex for simple tasks like providing a webservice interface (REST/SOAP) The solution should contain everything needed to create a new project and describe the concepts of the used tools/frameworks.
1 answer

Building a webapp using java

If you want to build a new webapp from scratch you should use a building tool and a framework for the webapplication part.

I suggest using maven as building and dependency management tool.
With maven you just have to configure which libraries you want to use and it will download the library and it's sources (if available) automatically for you. Even the classpath is handled by maven.

As Framework for webapplications Spring-MVC is a good choice.
Just go to the spring-mvc homepage and get the needed dependencies for maven and you have everything you need to start.

To get Spring to work in the application server you have to do the following:

  • Register the SpringContextLoaderListener in the web.xml of your web application
  • Register the Servlet for all URL-Pattern you want to serve with your web app
  • In the application concext you have to register an URL-Handler
  • Create the Controller beans in the application context or configure the package scanning
  • Create the Controller classes

In the Controller classes you can now register methods for specific URLs.

Now you have everything you need for a REST web application.

For a more detailed description of each step look at the official spring tutorial: http://docs.spring.io/docs/Spring-MVC-step-by-step/

Taggings: