使用spring获取项目的绝对路径,就算打JAR包一样获得当前项目的绝对路径
搞死了,哈哈,不过弄出来了
核心代码
package com.hansci.client.action.authority;import java.io.IOException;import java.util.Properties;import com.hansci.client.util.Constant;import com.hansci.client.util.PropertiesLoader;import com.hansci.client.webservice.LoginAuthService;import com.opensymphony.xwork2.Action;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.interceptor.AbstractInterceptor;public class UserAuthorityInterceptor extends AbstractInterceptor {private static final long serialVersionUID = -3929030161999051802L;public String intercept(ActionInvocation invocation) throws Exception { //创建ActionContext实例@SuppressWarnings("unused")ActionContext ctx = ActionContext.getContext();//获取user-client中得到的用户登录的sessionID的属性 LoginAuthService service = new LoginAuthService(); Properties p; String loginPath=""; String operatePath=""; try { p = PropertiesLoader.getProperties("");//鍙傛暟涓虹┖鏃? 璁块棶resource.properties鏂囦欢 loginPath=PropertiesLoader.getStringProperty(p, Constant.AUTHORITY_LOGIN_PATH,"null") ; System.out.println(loginPath); operatePath=PropertiesLoader.getStringProperty(p, Constant.AUTHORITY_OPERATE_PATH,"null") ; System.out.println(operatePath); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(service.login(loginPath)); if(null!=service.login(loginPath)&&!service.login(loginPath).equalsIgnoreCase("null")) {//如果没有登录,则需要返回重新登录 return invocation.invoke(); }else { return Action.LOGIN; }}}