Use spring 2.5.6 to build the mvc Framework
1. Project Dependency
All spring 2.5.6 packages: Full-set download of spring 2.5.6
Commons-logging-1.1.3.jar: commons-logging-1.1.3 download
2. Controller & Mapping starts from 2.5 and spring supports @ RequestMapping annotation to identify the matching url path.
HelloWorldController. java:
package controller;import org.springframework.stereotype.Controller;import org.springframework.ui.ModelMap;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;@Controller@RequestMapping("/welcome")public class HelloWorldController {@RequestMapping(method=RequestMethod.GET)public String helloWord(ModelMap model){System.out.println("hahaha ,nimeiyoushuozhimakaimen");model.addAttribute("message","fuck YOU@!!!");return "HelloWorldPage";}}
3. Spring Configuration
After the xml file is loaded, you can enable the annotation scan function and define the InternalResourceViewResolver ing rule to map the content returned in the controller to the front-end content.
Mvc-dispatcher-servlet.xml:
WEB-INF/pages/
.jsp
4. the Integrate Web application with Spring web server is loading the Web. when using xml, first define the welcome interface (default: index2.jsp, note the path writing method), declare ContextLoadListener and DispatcherServlet, and servlet ing rules.
Web. xml:
mySpringwork
/WEB-INF/index2.jsp
mvc-dispatcher
org.springframework.web.servlet.DispatcherServlet
1
mvc-dispatcher
/
contextConfigLocation
/WEB-INF/mvc-dispatcher-servlet.xml
org.springframework.web.context.ContextLoaderListener
5. JSP ViewsHelloWorldPage. jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
Insert title hereMessage : ${message} ${msg}