1.将war包放进tomcat安装目录的webapps目录下,war包就会自动解压

2.有两种方式可以访问到war包下的html

  • 方法1 我的war包中文件结构如下

Tomcat访问war包中的html

Tomcat访问war包中的html 

Tomcat访问war包中的html 

我要访问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;
    }
}

http://localhost:8080/SpringMVCTestDay1_2_war/printHello

相关文章:

  • 2021-11-23
  • 2021-11-23
  • 2021-04-27
  • 2021-04-22
  • 2021-05-06
  • 2021-09-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-26
  • 2021-11-23
  • 2021-10-30
  • 2021-06-15
  • 2021-07-11
  • 2021-12-03
  • 2022-12-23
相关资源
相似解决方案