/**
* 返回项目在磁盘上的绝对路径
*
* @param request
* @param path
* @return
*/
public static String getAppPath(HttpServletRequest request, String path) {
if (isEmpty(path))
return null;
* 返回项目在磁盘上的绝对路径
*
* @param request
* @param path
* @return
*/
public static String getAppPath(HttpServletRequest request, String path) {
if (isEmpty(path))
return null;
return request.getSession().getServletContext().getRealPath(path);
}
注:直接request.getRealPath("/ads");会获取编译器的警告
/**
* 返回当前项目的基本访问路径 比如: http://localhost/xhServer/
*
* @param request
* appBaseUrl (例如xhServer目录下的user_photos)
* @return
*/
public static String getBaseUrl(HttpServletRequest request,
String appBaseUrl) {
String baseUrl = request.getScheme() + "://" + request.getServerName()
+":" + request.getServerPort()+ request.getContextPath() + "/";
if (isNotEmpty(appBaseUrl))
baseUrl += appBaseUrl + "/";
return baseUrl;
}
若有其他需要请参考:http://wenku.baidu.com/view/54ca0e6748d7c1c708a145aa.html百度文库