标签:ring rect cto except include 需要 main extend extends
Properties
<!--在pom build中配置resources,来防止我们资源导出失败的问题-->
<build>
<resources>
<resource>
<directory>src/main/resouces</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
1.在java目录下properties
2.在resources目录下新建properties
发现:都被打包到了同一个路径下:classes 我们俗称这个路径为classpath
思路:需要一个文件流:
properties:
uersname=asdas
password=1asdasd
class:
public class Servletdome01 extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
InputStream is = this.getServletContext().getResourceAsStream("/WEB-INF/classes/com/hao/selever02/aa.properties");
Properties properties = new Properties();
properties.load(is);
String uersname = properties.getProperty("uersname");
String password = properties.getProperty("password");
resp.getWriter().print(uersname+password);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doPost(req, resp);
}
}
循循渐进02篇 maven Properties 读取资源文件
标签:ring rect cto except include 需要 main extend extends
原文地址:https://www.cnblogs.com/huhao2000/p/11920711.html