JAVA类中获取项目路径】的更多相关文章

在java web项目中获取项目的src/main/resource下的文件路径 当前类名.class.getClassLoader().getResource("/").getPath(); 比如我的当前类名叫Demo 那么: Demo.class.getClassLoader().getResource("/").getPath();…
WEB-INF路径 String path = WsTestBOImpl.class.getClass().getResource("/").getPath(); path = path.substring(1, path.indexOf("classes")); web-inf 下面的classses路径(也就是src路径) String path = WsTestBOImpl.class.getClass().getResource("/")…
一.获取项目路径: 1) String path = request.getContextPath() :// /TestMyEclipseString basePath = request.getScheme()+"://" +request.getServerName()+ ":" +request.getServerPort()+ path+"/";http://127.0.0.1:8080/TestMyEclipse/ 2) 路径是:&l…
Javaweb工程中,有时候需要自己手动的去读取classpath下面的配置文件,这里总结一点读取classpath路径的方法,分享一下. 方法一: String path = Test.class.getResource("/").toString(); System.out.println("path = " + path); 此方法在tomcat下面没有问题,可以取到WEB-INF/classes path = file:/home/ngidm_db2/AS_…
//从spring容易中获取bean public static Object getBean(String beanName){ ApplicationContext context = ContextLoader.getCurrentWebApplicationContext(); return context.getBean(beanName); } //获取ServletContext public static ServletContext getServletContext(){ W…
private static String getWebInfPath() { URL url = 当前类.class.getProtectionDomain().getCodeSource().getLocation(); String path = url.toString(); int index = path.indexOf("WEB-INF"); if (index == -1) { index = path.indexOf("classes"); } i…
//立即执行的js (function() { //获取contextPath var contextPath = getContextPath(); //获取basePath var basePath = getBasePath(); //将获取到contextPath和basePath分别赋值给window对象的g_contextPath属性和g_basePath属性 window.g_contextPath = contextPath; window.g_basePath = basePa…
起因是我想要获取一个相对路径,需要用到servletContext的getRealPath()方法,于是上网搜索,找到两种方法来获取ServletContext. 方法1:第一种方法是这样的: ServletActionContext.getServletContext(): 或者ServletContext servletContext= req.getServletContext();其中req是一个HttpServletRequest对象. 上述两种方法第一种局限于Struts中使用,且两…
//application.properties中设置:(file.path=static/qrfile/)//保存到static文件夹下的qrfile目录@Value("${file.path}")private String path; //文件路径String path = System.getProperty("java.class.path");int firstIndex = path.lastIndexOf(System.getProperty(&qu…
在jsp中加上 <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> 然后在jsp中的其他地方都可以通过  <%=bathPath%> 的方式来引用  在js中直接定义成变量使…