使用jsp覆盖文本文件

时间:2014-04-22 02:56:37

标签: java jsp web

我试图通过插入6行不同的数据来覆盖包含6行数据的文本文件。

这是我的表格。

<form method="POST" action="write.jsp">
    Name: <input type="text" name="name1"  size="20" /><br> 
    Price: <input type="text" name="price"  size="20" /><br> 
    Due time: <input type="text" name="DueTime"  size="20" /><br> 
    Location: <input type="text" name="Location"  size="20" /><br> 
    Photo Url: <input type="text" name="url"   size="20" /><br> 
    Description: <input type="text" name="desc"  size="20" /><br> 
    <input type="submit" name="submit" onclick="window.close()"/>
</form>

用户点击提交后,会转到write.jsp,如下所示。

String name = request.getParameter("name1");
String price = request.getParameter("price");
String DueTime = request.getParameter("DueTime");
String Location = request.getParameter("Location");
String url = request.getParameter("url");
String desc = request.getParameter("desc");

String paths="somepath/hotel1.txt"; 

FileWriter filewriter = new FileWriter(paths, true);

filewriter.write(name + System.getProperty("line.separator"));
filewriter.write(price + System.getProperty("line.separator"));
filewriter.write(DueTime + System.getProperty("line.separator"));
filewriter.write(Location + System.getProperty("line.separator"));
filewriter.write(url + System.getProperty("line.separator"));
filewriter.write(desc + System.getProperty("line.separator"));
filewriter.close();

但不管怎么说它确实有效,任何人都可以帮我解决这个问题吗?

0 个答案:

没有答案