Use spring 2.5.6 to build the mvc Framework

Source: Internet
Author: User

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} 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.