windows,linux路劲符号问题:
File file=new File(homePath+"//WEB-INF//classes//" + filePathName);
这种不需要加file:///
1.
windows 左斜杠,右斜杠都可以
linux 右斜杠
windows
\\用3根\\\,用两根的话会报D盘找不到之类
//DocumentBuilder.parse java.net.UnknownHostException: D
systemParameter.setTransFile("file:\\\"+homePath + systemParameter.getTransFile());
systemParameter.setTradeFile("file:\\\"+homePath + systemParameter.getTradeFile());
systemParameter.setCommFile("file:\\\"+homePath + systemParameter.getCommFile());
linux,windows
digester.addBeanPropertySetter("system/smsaddress/smsrespxmladdr", "respSMSXml");
logger.info("=======homePath=================="+homePath);
File file=new File(homePath+"//WEB-INF//classes//" + filePathName);
digester.parse(file);
logger.info("=======filePathName=================="+homePath+"WEB-INF\\classes\\" + filePathName);
//windows,LINUX
//用3根///,用两根的话会报D盘找不到之类
systemParameter.setTransFile("file:///"+homePath + systemParameter.getTransFile());
systemParameter.setTradeFile("file:///"+homePath + systemParameter.getTradeFile());
systemParameter.setCommFile("file:///"+homePath + systemParameter.getCommFile());
配置文件/
拼接后\/可以混用,
/\可以
/home/tomcat7/webapps/hb_telesale\WEB-INF/classes/config/xml/trdef.xml
2.
如果是访问文件夹,没有协议,加file://(无论windows还是linux)
no protocol: /home/tomcat7/webapps/hb_telesale/WEB-INF/classes/config/xml/trdef.xml
3.
servlet典型用法
这里面的参数是init方法的参数
system.xml 这个里面拿
public class LoadSystemConfigParameterServlet
extends HttpServlet
{
private static final long serialVersionUID = 5130241834911695773L;
private static final Log logger = LogFactory.getLog(LoadSystemConfigParameterServlet.class);
public void init(ServletConfig config)
throws ServletException
{
String filePathName = config.getInitParameter("filepathname");
String homePath = config.getServletContext().getRealPath("");
SystemParameter systemParameter = SystemParameter.getInstance();
systemParameter.setSystemHomePath(homePath);
}
}
项目发布地址获取方法
String homePath = config.getServletContext().getRealPath("");
linux是/home/tomcat7/webapps/hb_telesale
windows是D:\ideahblj\target\hb_telesale
4.
classpath:==//WEB-INF//classes//
注意:发布的时候最好之前的文件夹删除