Servlet_GetRealPath 通过资源相对路径获取所处服务器下全路径
//获取文件全路径的Servlet类 public class getRealPathServlet extends HttpServlet { //Servlet doGet请求 @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { //HttpServletResponse.getServletContext().getRealPath("资源相对路径") //返回服务器下的绝对路径 String path = req.getServletContext().getRealPath("/index.jsp"); //页面打印 resp.getOutputStream().write(path.getBytes()); } }
Servlet_GetRealPath 通过资源相对路径获取所处服务器下全路径
最新推荐文章于 2022-08-12 23:19:42 发布