重定向动态获取虚拟目录

tech2025-12-21  0

由于在重定向中会使用到虚拟目录,直接写死虚拟目录可能会发生一些问题; 所以我们一般先使用request对象的getContextPath()方法获取虚拟目录; String contextPath = request.getContextPath(); 然后再使用重定向; response.sendRedirect(contextPath + “不带虚拟路径的绝对路径”);

最新回复(0)