服务器路径的获取
程序员文章站
2022-05-09 15:00:25
...
方法:String getRealPath(String path)
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//1.context对象的获取
ServletContext servletContext = this.getServletContext();
//获取文件的服务器路径
//src目录下资源访问
String realPath4 = servletContext.getRealPath("/WEB-INF/classes/a.txt");
//web目录下资源访问
String realPath2 = servletContext.getRealPath("/b.txt");
//WEB-INF目录下资源访问
String realPath3 = servletContext.getRealPath("/WEB-INF/c.txt");
System.out.println(realPath4);
System.out.println(realPath2);
System.out.println(realPath3);
}
下一篇: 陕西省是如何得名的?探索陕西省历史的由来