spring on the web

a client’s request passing spring mvc: a request (user request a web page) first sent to front controller/DispatcherServlet (a servlet which is responsible to designates tasks to different mvc components), front controller consult handler mappings to pass the request to the correct controller; then controller send the request to its service objects & wait for response; the response is some database raw data and view name (model&view name) and is not user-readable; then controller pass the model&view name back to front controller & front controller consult view resolver where to render the view, finally implement the view and send response back to the client.

set up java-based spring mvc: define a webAppInitializer app (create/register/map the DispatcherServlet); define a spring mvc config file (enables component scan for controllers, configure a JSP view resolver..); define a model class & a jsp page. see: https://samerabdelkafi.wordpress.com/2014/08/03/spring-mvc-full-java-based-config/ for a detailed full java based spring mvc example.

write a simple controller: annotate the controller class with @Controller (such that the component scanner in the spring mvc config file can automatically declare it as a bean, @Component also works);  create a method inside the controller class & annotate the method with @RequestMapping, the method will then return the view name to DispatcherServlet (@RequestMapping handles HTTP requests for a certain request path)

Leave a Reply

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