java web(spring mvc) 获取请求host 和 如何获取静态页的相对路径

时间:2022-05-15 15:50:06

1.获取请求host

StringBuffer url = request.getRequestURL();
String tempContextUrl = url.delete(url.length() - request.getRequestURI().length(), url.length()).toString();

2.获取静态页的相对路径

String path=request.getSession().getServletContext().getRealPath("相对路径");