go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  MVC -- View
 
Subject: MVC -- View
Author: WebSpider
In response to: MVC -- Controller
Posted on: 11/23/2017 02:36:50 AM


home.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<html>
    <head>
	<title>Home</title>
    </head>
    <body>
        <h1>Hello world!</h1>

        <P>The time on the server is ${serverTime}.</P>
    </body>
</html>


 

> On 11/23/2017 02:35:24 AM WebSpider wrote:

@Controller
public class HomeController {
	/**
	 * Simply selects the home view to render by returning its name.
	 */
	@RequestMapping(value = "/index", method = RequestMethod.GET)
	public String home(Locale locale, Model model) 
        {
		String server_timestamp = new Date().toString();
		model.addAttribute("serverTime", server_timestamp);
		return "home";
	}
}


With the above code, the Spring Framework can do following jobs:
  • @Controller -- The class HomeController has been annotated as a controller
  • @RequestMapping(value = "/index", method = RequestMethod.GET) -- The HTTP GET request http://<host>:<port>/<context>/index will be served by the annotated method home(Locale locale, Model model)
  • Locale locale, Model model -- Dependencies will be injected silently under the hood by Spring Framework
  • return "home" -- The view will be rendered by "<prefix>home<suffix>" with the help of dispatch-servlet.xml





    References:

  •  


     
    Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
     
    Get your own forum today. It's easy and free.