从servlet访问方法时发现文件未找到异常

时间:2015-03-03 10:34:51

标签: java

我有一个带有文件路径的java类。当我尝试将其作为java应用程序运行时它工作正常但是当我尝试从servlet中访问该类中的方法时,我收到错误java.io.FileNotFoundException < / p>

Java Class

public class PropertiesManager {


 static Properties prop =new Properties();
static String PROPERTY_FILENAME = "Dashboard1.0/src/server_url.properties";

public static void main(String[] args) {
    loadProperty();
    System.out.println(prop.getProperty("DemoApps_DataBase"));
    updateProperty();
}

public static void loadProperty(){

    InputStream input = null;

    try {

     FileInputStream file= new FileInputStream(PROPERTY_FILENAME);
        // load a properties file
        prop.load(file);

    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

public static void updateProperty(){
    OutputStream output = null;

    try {

        output = new FileOutputStream(PROPERTY_FILENAME);

        // set the properties value
        prop.setProperty("DemoApps_DataBase", "Oracle");
        System.out.println(prop.getProperty("DemoApps_DataBase"));

        // save properties to project root folder
        prop.store(output, null);

    } catch (IOException io) {
        io.printStackTrace();
    } finally {
        if (output != null) {
            try {
                output.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}

Servlet类

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    String name=request.getParameter("appName");
    String link=request.getParameter("appLink");
    String database=request.getParameter("appDB");
    String webServices=request.getParameter("appWebService");
    PropertiesManager.loadProperty();
    PropertiesManager.updateProperty();
    RequestDispatcher rd=request.getRequestDispatcher("updateappstatus.jsp");
    rd.forward(request,response);       

}

0 个答案:

没有答案