String path = request.getContextPath();//相对路径
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
request.setAttribute("path",path);//一般在页面的开头进行设置,一直设置path
例如 :

本文介绍了在Web应用中如何使用HttpServletRequest对象获取当前应用的基础路径,包括相对路径和完整URL路径,这对于页面资源加载和API调用至关重要。
String path = request.getContextPath();//相对路径
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
request.setAttribute("path",path);//一般在页面的开头进行设置,一直设置path
例如 :


被折叠的 条评论
为什么被折叠?