本文整理汇总了Java中org.springframework.web.util.WebUtils.getRealPath方法的典型用法代码示例。如果您正苦于以下问题:Java WebUtils.getRealPath方法的具体用法?Java WebUtils.getRealPath怎么用?Java WebUtils.getRealPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.util.WebUtils
的用法示例。
在下文中一共展示了WebUtils.getRealPath方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFile
import org.springframework.web.util.WebUtils; //导入方法依赖的package包/类
/**
* This implementation resolves "file:" URLs or alternatively delegates to
* {@code ServletContext.getRealPath}, throwing a FileNotFoundException
* if not found or not resolvable.
* @see javax.servlet.ServletContext#getResource(String)
* @see javax.servlet.ServletContext#getRealPath(String)
*/
@Override
public File getFile() throws IOException {
URL url = this.servletContext.getResource(this.path);
if (url != null && ResourceUtils.isFileURL(url)) {
// Proceed with file system resolution...
return super.getFile();
}
else {
String realPath = WebUtils.getRealPath(this.servletContext, this.path);
return new File(realPath);
}
}
示例2: getRootPath
import org.springframework.web.util.WebUtils; //导入方法依赖的package包/类
public static String getRootPath(String resource) {
HttpServletRequest request =ThreadContextHolder.getHttpRequest() ;
try {
return WebUtils.getRealPath(request.getSession().getServletContext(), resource);
} catch (FileNotFoundException e) {
e.printStackTrace();
return "";
}
}
示例3: initLogging
import org.springframework.web.util.WebUtils; //导入方法依赖的package包/类
/**
* Initialize logback, including setting the web app root system property.
*
* @param servletContext the current ServletContext
* @see WebUtils#setWebAppRootSystemProperty
*/
public static void initLogging(ServletContext servletContext) {
// Expose the web app root system property.
if (exposeWebAppRoot(servletContext)) {
WebUtils.setWebAppRootSystemProperty(servletContext);
}
// Only perform custom logback initialization in case of a config file.
String location = servletContext
.getInitParameter(CONFIG_LOCATION_PARAM);
if (location != null) {
// Perform actual logback initialization; else rely on logback's
// default initialization.
try {
// Return a URL (e.g. "classpath:" or "file:") as-is;
// consider a plain file path as relative to the web application
// root directory.
if (!ResourceUtils.isUrl(location)) {
// Resolve system property placeholders before resolving
// real path.
location = SystemPropertyUtils
.resolvePlaceholders(location);
location = WebUtils.getRealPath(servletContext, location);
}
// Write log message to server log.
servletContext.log("Initializing logback from [" + location
+ "]");
// Initialize without refresh check, i.e. without logback's
// watchdog thread.
LogbackConfigurer.initLogging(location);
} catch (FileNotFoundException ex) {
throw new IllegalArgumentException(
"Invalid 'logbackConfigLocation' parameter: "
+ ex.getMessage());
}
}
}
示例4: getFilePath
import org.springframework.web.util.WebUtils; //导入方法依赖的package包/类
private String getFilePath(String dir) throws FileNotFoundException {
return WebUtils.getRealPath(servletContext, dir);
}