How can I get real path for file in my WebContent folder?

前端 未结 9 1027
既然无缘
既然无缘 2020-12-16 02:33

I need to get real path for file in my WebContent directory, so that framework that I use can access that file. It only takes String file as attribute, so I need to get the

9条回答
  •  庸人自扰
    2020-12-16 03:11

    Include the request as a parameter. Spring will then pass the request object when it calls the mapped method

    @RequestMapping .....
    public String myMethod(HttpServletRequest request) {
       String realPath = request.getRealPath("/somefile.txt");
       ...
    

提交回复
热议问题