How do I access file in WEB-INF in JSP?

后端 未结 2 2127
無奈伤痛
無奈伤痛 2020-12-19 19:59

I am using Tomcat. I would like to put the config file in WEB-INF instead of the default root class path which is WEB-INF/classes. Currently I put

2条回答
  •  情书的邮戳
    2020-12-19 20:29

    You can use getServletConfig() method return an instance of ServletConfig.

    ServletContext sc=getServletConfig().getServletContext();
    

    EDIT:

    public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException{
      ServletContext sc=getServletContext();
      ...
    }
    

提交回复
热议问题