获取输入栏地址
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort();
获取所有参数:request.getQueryString()。
获取当前项目根路径
System.getProperty("user.dir")
单例类
public class Singleton {
/* private static Singleton instance = new Singleton(); //已经自行实例化
private Singleton(){} //私有的默认构造
public static Singleton getInstance() { //静态工厂方法
return instance;
} */
private static Singleton instance = null;
private Singleton(){}
public static synchronized Singleton getInstance() {
//也可以这样写:synchronized public static Singleton getInstance() {
if (instance == null){
instance = new Singleton();
}
return instance;
}
}
读取properties
ResourceBundle bundle = ResourceBundle.getBundle(包名.文件名);//文件名不加后缀
String s = bundle.getString(文件里的键名);
---------------------------------------------------------------------------------------------------------------------
InputStream in = new BufferedInputStream(new FileInputStream(配置文件));//实例化出配置文件
或者InputStream in = ClassLoader.getSystemResourceAsStream("包名/文件名");//文件名加后缀
或者InputStream in = 本类类名.class.getClassLoader().getResourceAsStream("包名/文件名");//文件名加后缀
Properties p = new Properties();
p.load(in);
in.close();
p.getProperty(文件里的键名)
文件分隔符
File.separator