2015-03-02 39 views
0

我有一個servlet,我獲取所有表單值並將其存儲在變量中,在該servlet本身中,我試圖更新我的屬性文件。但屬性文件沒有得到更新。任何人都可以告訴我如何訪問我的表單值並更新我的屬性文件。使用表單值更新屬性文件不起作用

的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"); 
    FileInputStream in = new FileInputStream("server_url.properties"); 
    Properties props = new Properties(); 
    props.load(in); 
    FileOutputStream outputStream = new FileOutputStream("server_url.properties"); 
    props.setProperty("DemoApps_Links", link); 
    props.setProperty("DemoApps_DataBase", database); 
    props.store(outputStream , null); 
    outputStream .close(); 
System.out.println(link); 
System.out.println(database); 
} 
+0

你在Servlet中正確地獲取參數嗎? – Ved 2015-03-02 12:29:08

+0

在關閉它之前嘗試刷新流:outputStream.flush(); – flayn 2015-03-02 13:06:39

回答

0

關閉輸入流,然後再更新屬性。

**in.close();** 
    Properties props = new Properties(); 
    props.load(in); 
    FileOutputStream outputStream = new FileOutputStream("server_url.properties"); 
    props.setProperty("DemoApps_Links", link); 
    props.setProperty("DemoApps_DataBase", database); 

假設您正在獲取鏈接和數據庫參數。

+0

我得到這個異常'java.io.IOException:流關閉' – V02169194 2015-03-03 04:16:18

+0

把它放在'props.load(in);' – Ved 2015-03-03 12:30:17