写在properties文件里啊
 InputStream is = getClass().getResourceAsStream("aa.properties");
 Properties dbProps = new Properties();
 try {
 dbProps.load(is);
 }catch (Exception e) {
 }

解决方案 »

  1.   

    String rootPath      = this.getServletContext().getInitParameter("RootPath"); //上下文根路径随便建个config目录不好吗?
      

  2.   

    The standard practice is to put your config files (.properties files) under \web-inf\classes (this folder is in the classpath by definition). In your code, use ResourceBundle to load it.For example, if you have config.properties under \web-inf\classess, your code looks like this:    ResourceBundle bundle = ResourceBundle.getBundle("config");To get a particular value for a key:    String myConfig = (String)bundle.getObject("myConfigKey");
      

  3.   

    Properties文件就可以实现这功能,本身就提供了Properties这样一个目录的.