配置文件的位置
- src目录下
- Web目录下
- WEB-INF目录下
@WebServlet("/servletContextDemo5")
public class ServletContextDemo5 extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//获取httpServlet对象
ServletContext context = this.getServletContext();
//获取文件的服务器路径
String realPath = context.getRealPath(".b.txt");
System.out.println(realPath);
File file=new File(realPath);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
}