1.将war包放进tomcat安装目录的webapps目录下,war包就会自动解压
2.有两种方式可以访问到war包下的html
- 方法1 我的war包中文件结构如下
我要访问staticPage.html,在浏览器中,访问的URL为:http://localhost:8080/SpringMVCTestDay1_2_war/html/staticPage.html
- 方法二 由于在我的控制器代码中,实现了方法和url的映射,所以也可以通过这个/printHello访问页面
@Controller
public class StaticController {
//@RequestMapping实现方法和url的映射,访问的时候,进入了这个url,也就进入了这个方法
@RequestMapping(value="/printHello",method = RequestMethod.GET)
public ModelAndView printHello(ModelMap model) {
ModelAndView modelAndView = new ModelAndView();
//相当于request的setAttribute,在前端通过itemList取数据
modelAndView.addObject("itemList","132465");
//指定视图,视图解析器就根据这个视图名和配置的前缀、后缀名来寻找视图文件
modelAndView.setViewName("staticPage");
return modelAndView;
}
}