例如,

import java.io.File;
import java.io.FileInputStream; import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import com.aisino.qysds.common.constant.ERRORConstants;
import com.aisino.qysds.common.exception.SysException; /**
* 获取相对项目Web-app 下的路径的文件
* @author wdh
*
*/
public class WebUtil { public static String getWebPath(){
String line = File.separator;
ServletRequestAttributes aRequestAttributes=(ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
HttpServletRequest request =aRequestAttributes==null?null:aRequestAttributes.getRequest();
String webpath=request.getServletContext().getRealPath("/")+line;
return webpath;
} }

获取webapp下  execl 文件

String line = File.separator;
File file = new File(webUtil.getWebpath()+line+"excel"+line+"文件名.xls");

Java 获取Web项目相对webapp地址的更多相关文章

  1. Java获取web项目路径

    File f = new File(WebPath.class.getResource("/").getPath()); String path = f.getParentFile ...

  2. java获取web项目下文件夹的路径方法

    方法一: String realPath=request.getSession().getServletContext() .getRealPath("upload"); 方法二: ...

  3. Java获取Web服务器文件

    Java获取Web服务器文件 如果获取的是服务器上某个目录下的有关文件,就相对比较容易,可以设定死绝对目录,但是如果不能设定死绝对目录,也不确定web服务器的安装目录,可以考虑如下两种方式: 方法一: ...

  4. idea中的java web项目(添加jar包介绍)和java maven web项目目录结构

    java web项目 web项目下web根目录名称是可以更改的 idea中新建java web项目,默认src为Sources Root,当然也可以手动改,在Sources Root下右键只能新建Pa ...

  5. Spring中获取web项目的根目录

    spring 在 org.springframework.web.util 包中提供了几个特殊用途的 Servlet 监听器,正确地使用它们可以完成一些特定需求的功能; WebAppRootListe ...

  6. (转)关于java和web项目中的相对路径问题

    原文:http://blog.csdn.net/yethyeth/article/details/1623283 关于java和web项目中的相对路径问题 分类: java 2007-05-23 22 ...

  7. java做web项目比较多

    WEB就是轻量级:如果要炫,FLEX或即将普及的html5.0都能做到像C/S那样. java做web项目比较多:如果是桌面程序,还是走C/S比较成熟. 如果是B/S架构的,后台还是JAVA,前台可以 ...

  8. 获取 web 项目的绝对路径

    获取 web 项目的绝对路径 <% String path = request.getContextPath(); String basePath = request.getScheme()+& ...

  9. Java 获取客服端ip地址

    Java 获取客服端ip地址 /** * <html> * <body> * <P> Copyright 1994 JsonInternational</p& ...

随机推荐

  1. mathjax;latex

    \lfloor $\lfloor$ \rfloor $\rfloor$ \sum_{i=1}^{n} $\sum_{i=1}^{n}$ \mu $\mu$ \mid $\mid$ \Leftright ...

  2. spring boot test MockBean

    使用spring boot , MockBean @RunWith(SpringRunner.class) @SpringBootTest(classes = Application.class) p ...

  3. JS——数组、==和===的区别

    创建数组的方式: 1) <script type='text/javascript'> var aRr = new Array(1,2,3,4,'abc',3) </script&g ...

  4. k8s的ingress使用

    ingress 可以配置一个入口来提供k8s上service从外部来访问的url.负载平衡流量.终止SSL和提供基于名称的虚拟主机. 配置ingress的yaml: 要求域名解析无误 要求servic ...

  5. easyui datagrid关于分页的问题

    easyui框架中datagrid可以很好的来展示大量的列表数组,但是由于datagrid一般都是从控件本身传递一个页码给后台,后台进行处理. 但是,最近项目跟webgis有关,数据查询直接是从服务中 ...

  6. [JQuery] Using skill in JQuery

    Using skill of JQuery 获取兄弟节点 $('#id').siblings() 当前元素的所有兄弟节点 $('#id').prev() 当前元素的前一个兄弟节点 $('#id').p ...

  7. Linux下安装软件遇见的问题汇总

    1.安装monodevelop 安装环境Linux Mint17.1 在软件在中心直接安装monodevelop,安装完成后直接启动界面“一闪而过”,解决办法: 软件中心安装 mono-complet ...

  8. Ubuntu下eclipse无法识别手机驱动(以小米2S为例子)

    google官方开发向导里对Android手机已经设置了允许安装非market程序,并且处于usb调试模式,但是仍然在usb连接电脑后无法被识别的问题作了解释. 在Ubuntu Linux环境下需要添 ...

  9. Duplicate Emails

    Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...

  10. hibernate课程 初探单表映射1-2 ORM定义

    1 什么是ORM? ORM(Object / RelationShip Mapping) 对象/关系映射 面向对象编程(OOP)最终要把对象信息保存在关系性数据库中,要写好多sql语句.这与面向对象编 ...