在web应用程序中经常需要获取服务器的绝对路径,通过实现Spring的相关接口可以满足这一要求.
其工具类的代码如下:
复制代码
在配置文件中需要加入相关bean的配置:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19package org.sklse.jz.util; import java.io.FileNotFoundException; import javax.servlet.ServletContext; import org.springframework.web.context.ServletContextAware; import org.springframework.web.util.WebUtils; public class WebUtil implements ServletContextAware{ public static String DIR=null; public static ServletContext servletContext=null; @Override public void setServletContext(ServletContext context) { try { servletContext=context; DIR = WebUtils.getRealPath(context, "/WEB-INF/"); } catch (FileNotFoundException e) { e.printStackTrace(); } } }
<bean class="org.sklse.jz.util.WebUtil"/>
最后
以上就是干净铅笔最近收集整理的关于在Spring框架中获取服务器绝对路径的全部内容,更多相关在Spring框架中获取服务器绝对路径内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复