Java 获取Web项目相对webapp地址
例如,
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");
版权声明:如需转载,请注明!PS:如是转载随便,请忽略