java.io.FileNotFoundException:db.properties(系统找不到指定的路径)
我已经编写了一个基本的jsp代码,用于存储和检索数据库中的数据。 在此之前,我正在检查用户验证 当我点击提交按钮时,它将重定向到我的jsp页面 我已经分别编写了一个db.properties文件 当我给出读取属性文件的完整路径时,程序运行良好。(这不是实现如下硬编码的最佳方式) FileInputStream in=新的FileInputStream(“C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ServiceDisplay\db.properties”) 但是当我只指定“db.properties”时 (FileInputStream in=newfileinputstream(“db.properties”);)程序未执行我得到文件未找到异常 请不要选择此属性文件仅在当前工作目录中。(即,我的db.properties文件和我的jsp文件位于servicesplay 我试图将文件名更改为“//db.properties”、“/db.properties”、“/db.properties”、“\db.properties”、.\db.properties、../db.properties”、“.\db.properties”。java.io.FileNotFoundException:db.properties(系统找不到指定的路径),java,jsp,Java,Jsp,我已经编写了一个基本的jsp代码,用于存储和检索数据库中的数据。 在此之前,我正在检查用户验证 当我点击提交按钮时,它将重定向到我的jsp页面 我已经分别编写了一个db.properties文件 当我给出读取属性文件的完整路径时,程序运行良好。(这不是实现如下硬编码的最佳方式) FileInputStream in=新的FileInputStream(“C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ServiceDi
但是我仍然得到java.io.FileNotFoundException:db.properties文件“ServiceDisplay\db.properties”在您的资源目录中,要加载此文件,必须使用
GetResourcesCeasStream
。下面的代码示例:
ServletContext context = request.getSession().getServletContext();
InputStream is = context.getResourceAsStream("/db.properties");
你能把这个文件添加到你的类路径吗?