springmvc学习(二):视图定位

作用是把jsp或其他文件定位到指定的文件夹

一、修改springmvc-servlet.xml

新增这一段:


        
        
    
 
  

配置文件变为如下:




 
    
        
        
    
 
    
        
            
                indexController
            
        
    
    


二、修改IndexController

ModelAndView mav = new ModelAndView("index.jsp");变为

ModelAndView mav = new ModelAndView("index");

package controller;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
 
public class IndexController implements Controller {
    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView("index");
        mav.addObject("message", "Hello Spring MVC");
        return mav;
    }
}


三、移动index.jsp

移动到page文件夹下

你可能感兴趣的:(java,springmvc)